lxXTaCoXxl 26 Posting Whiz in Training

I am trying to figure out how to convert hexadecimal values into mips instructions but I am not having any luck. From my understanding you have to first break the value down to machine level (binary) and then use that result to determine the instruction by converting each section of bits for the instruction type back to hexadecimal. For example:

AFBF0000 should break down to 10101111101111110000000000000000 in binary. Just looking at this I can tell that it is an I type instruction and the first six bits give me the opcode. So 101011 gives me 2B in hex which by my list of opcodes is sltu (this raises issue number one); according to the chart the next five bits (11101) should give me the first source register used by this instruction which turns into 1d in hex and by my chart is the stack pointer (sp). The following five bits (11111) should give me the second source register in the instruction which when converted becomes 1f which is ra. The remaining 16 bits for this I type instruction have a zero value giving us the final four zeroes in our hex value. According to my assembler this should actually be the instruction sw ra $0000(sp) but it is not in my case; I feel that either I am doing something wrong when converting my values or the opcodes in my list are either wrong or not in the correct format. All help is appreciated and thanks in advance for reading.

lxXTaCoXxl 26 Posting Whiz in Training

Why not use Type.GetMethods to get just the methods instead of searching for keywords in the file. I took a second to write an example (though not as detailed as yours) it can be modified to implement with opening a specific file.

        private void button1_Click(object sender, EventArgs e) {
            ListMethods(typeof(int));
        }

        private void ListMethods(Type t) {
            foreach (var m in t.GetMethods()) {
                var p = string.Join
                    (", ", m.GetParameters()
                                 .Select(x => x.ParameterType + " " + x.Name)
                                 .ToArray());

                richTextBox1.Text += (string.Format("{0} {1} ({2})\n",
                                  m.ReturnType,
                                  m.Name,
                                  p));
            }
        }

Untitled-3.jpg

Obviously with mine you could add a drop down menu or use radio buttons to select which type of method you wish to look for (and a little more work has to be done to reveal private and protected methods) and if you use a drop down menu just add an all option. Just a thought, but yours is a good approach as well. Nice work!

ddanbe commented: Thanks for your tip! +15
lxXTaCoXxl 26 Posting Whiz in Training

Why not add in a class for authentication and allow for modification through properties. Even if the class doesn't have everything needed for that particular case the user could always add what they need during implementation.

lxXTaCoXxl 26 Posting Whiz in Training

Validation assembly required?

lxXTaCoXxl 26 Posting Whiz in Training

I am trying to find ways to get the hex data from a file opened in a windows form using the open file dialog. I've done some reading and have found that .NET Framework used to have a byte viewer component built into System.Design that was a quick standard way to view the data needed; however upon trying this (ignorantly forgetting that most information found in the first page of Google's search engine for things like this are outdated 50% of the time) I found that System.Design.ByteViewer did not exist even after adding System.Design as a reference. I am prepared to write my own component to handle this in the long run anyways since I do not want it displayed in the traditional sense of a hex editor where the data is displayed via offsets.

In a standard hex editor we all know that data is displayed as:
00000000 12 34 56 78 12 34 56 78 12 34 56 78 12 34 56 78

I want mine to be more of a simpler approach to clean up my editor with emphasis on space and organization. Mine will have the downside of a longer list of data (in appearence) but will optimize work space:

00000000 12345678
00000004 12345678
00000008 12345678
0000000c 12345678

I like this view better because it allows me to stick with the overall idea of the application in a simpler form and still manage to get my end task done.

Has anyone else …

lxXTaCoXxl 26 Posting Whiz in Training

Sorry for the extremely late response, however t refers to the point in time you are looking for during the travel of the curve. To get x and y individually you would simply do the following:

float x = CurrentPoint(t, e1,c1,c2,e2).X;
float y = CurrentPoint(t, e1,c1,c2,e2).Y;

-Jamie

lxXTaCoXxl 26 Posting Whiz in Training

I developed this for my XNA games, some people like me enjoy recreating the things that are most useful in a GUI. To the best of my knowledge XNA Framework doesn't come with a built in keyboard for Windows based game development; though the Windows Phone and XBOX 360 development platforms have the keyboard built in to the system most of my games are desktop based so you can see the reasoning behind it.

lxXTaCoXxl 26 Posting Whiz in Training

It could probably be cleaned up a bit too. :)

lxXTaCoXxl 26 Posting Whiz in Training

The snippet provided will cover the basics of an on screen keyboard; the only things it doesn't have are numbers, symbols, and extra keys. This will give you the fundementals to build off of. It's written using Microsoft's XNA Framework, however it should be fairly simple to port over to a forms application. I don't really work with forms too often anymore, but in case you switch over to the Windows 8 platform be it Desktop or Phone, this could come in handy for some custom appearances.

Jamie - Studio 41

lxXTaCoXxl 26 Posting Whiz in Training

So in pseudocode it would be something like:

int List<T>::DataAt(int Index) {
    Node<T> *CurrentPointer = LastPointer;

    for (int i = 0; i < Index; i++)
        CurrentPointer = CurrentPointer->NextPointer;

    return CurrentPointer->Data;
}

And of course all my pseudocode has to be syntactically correct lol sorry; anyways that's from my understanding is that I'm putting the list in backwards and it's only reading from the front because that index will always be there?

lxXTaCoXxl 26 Posting Whiz in Training

Well I've known about operator overloading for a while now so thank you for reminding me how to do it, as for the random numbers; it doesn't have to be perfectly random, just random enough that it works. The problem is probably as histrungalot stated; I need to find another way to insert the nodes into the list because it's doing exactly what he demonstrated.

lxXTaCoXxl 26 Posting Whiz in Training

These are just some of the more useful #define statements I've used in C++. These are some of the statements you'll use the most (in the case of template<typename T> when you use it, you use it a lot!). So I figured I'd post it for others, even though a lot of the programmers probably already have this list.

Lucaci Andrew commented: -1
lxXTaCoXxl 26 Posting Whiz in Training

For some reason posting boxes are messing up on my end and I can't edit my post, it keeps highlighting areas I don't want highlighted. I don't know what's going on with it, but any help is still appreciated.

Thanks,
Jamie

lxXTaCoXxl 26 Posting Whiz in Training

I've been given a homework assignment in which I have to create a linked list, then store 25 random integers within it, after I've stored the values I have to find the sum of these 25 numbers, and then the floating point average of them. So for the most part this works. It stores the values into the list, but the member function I've created called "DataAt(int)" returning type of 'int' is only returning a value of 34 everytime. This is not what I need to assign the current sum and average outputs are:

sum = 850
avg = 34

So I need a little help with the matter because I don't seem to be able to find the problem; I've tried two different loops and and neither are wanting to work. The results should be the following based on the output from the items in the list:

sum = 1181
avg = 47.24

So anyone who can help with the matter is greatly appreciated. I've learned the main objective of the homework assignment, but I can't figure out what I'm doing wrong to retrieve data individually. For example in C# you can retrieve the data from a linked list at a specific location like you would with an array:

List<int> MyList;
int i = MyList[4]; // Valid

So I've been trying to figure it out since last night and can't seem to get it. Below is my source code and any help is appreciated in solving …

lxXTaCoXxl 26 Posting Whiz in Training

Okay so I got the application to successfully compile, however there is still a problem; the application is not printing anything I told it to in the main() function. It just sits there and I'm thinking it might be infinite loop or recursion because I can't even type anything into the terminal?

// Main.cpp
#include <iostream>
#include <string>
#include "Resistor.h"

using namespace std;

int main() {
    Resistor r1;
    int b1;
    int b2;
    int b3;
    int b4;

    cout << "Please input the color of the first three bands using the following numbers:\n";
    cout << "Black - 0\n";
    cout << "Brown - 1\n";
    cout << "Red - 2\n";
    cout << "Orange - 3\n";
    cout << "Yellow - 4\n";
    cout << "Green - 5\n";
    cout << "Blue - 6\n";
    cout << "Violet - 7\n";
    cout << "Gray - 8\n";
    cout << "White - 9\n";

    cin >> b1 >> b2 >> b3;

    cout << "Please input the color of the tolerance band color using the following numbers:\n";
    cout << "Gold - 0\n";
    cout << "Silver - 1\n";
    cout << "None - 2\n";

    cin >> b4;

    cout << "Your resistor is: " << r1.CalculateResistance(b1, b2, b3, b4);

    system("pause");
}

// Resistor.h
#include <string>
#include "Convert.h"

class Resistor {
    public:
        Resistor();
        int Bands[10];
        int Multipliers[10];
        int Tolerances[3];

        std::string CalculateResistance(int, int, int, int);
};

Resistor::Resistor() {
        // Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Gray, White
        for (int i = 0; i < 10; i++)
            Bands[i] = i;

        for (int x = 0; x < …
lxXTaCoXxl 26 Posting Whiz in Training

Okay so after looking at that link I threw together a class that follows the same principles. However it's giving me an error saying unresolved external symbol in Main.obj. I'll post the entire source and hopefully we can get this fixed. I appreciate all the help!

Error: error LNK2019: unresolved external symbol "public: int __thiscall Convert::ToInt32(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ToInt32@Convert@@QAEHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Resistor::CalculateResistance(int,int,int,int)" (?CalculateResistance@Resistor@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHHH@Z)

Location: Main.obj

Error: error LNK1120: 2 unresolved externals
Location: ResistorCalc.exe

// Main.cpp
#include <iostream>
#include "Resistor.h"

using namespace std;

int main() {
    Resistor r1;
    int b1;
    int b2;
    int b3;
    int b4;

    cout << "Please input the color of the first three bands using the following numbers:\n";
    cout << "Black - 0\n";
    cout << "Brown - 1\n";
    cout << "Red - 2\n";
    cout << "Orange - 3\n";
    cout << "Yellow - 4\n";
    cout << "Green - 5\n";
    cout << "Blue - 6\n";
    cout << "Violet - 7\n";
    cout << "Gray - 8\n";
    cout << "White - 9\n";

    cin >> b1 >> b2 >> b3;

    cout << "Please input the color of the tolerance band color using the following numbers:\n";
    cout << "Gold - 0\n";
    cout << "Silver - 1\n";
    cout << "None - 2\n";

    cin >> b4;

    cout << "Your resistor is: " << r1.CalculateResistance(b1, b2, b3, b4);

    system("pause");
}

// Resistor.h
#include <string>
#include "Convert.h"

class Resistor {
    public:
        Resistor();
        int Bands[10];
        int Multipliers[10];
        int Tolerances[3];

        std::string CalculateResistance(int, int, int, int);
};

Resistor::Resistor() { …
lxXTaCoXxl 26 Posting Whiz in Training

I'm trying to convert a number to a string then back to a number to perform math, then back to a string to return it to the user. I don't understand the problem because this is how my friend did it (that I can remember and it worked for him). Basically if someone can help me with this topic it would be apreciated!

std::string Resistor::CalculateResistance(int Digit1, int Digit2, int Multiplier, int Tolerance) {
    std::istringstream buffer;
    buffer >> Digit1;

    std::string x = buffer.str; // Problem
    buffer >> Digit2;
    x += buffer.str; // Problem

    double y = atof(x.c_str) * Multiplier; // Problem

    std::istringstream buffer2;
    std::string z = "";

    if (y > 999 && y < 999999) {
        y /= 1000;
        buffer2 >> y;
        z = buffer2.str + "KΩ" + Tolerances[Tolerance]; // Problem
        return z;
    }

    else if (y > 999999 && y < 999999999) {
        y /= 1000000;
        buffer2 >> y;
        z = buffer2.str + "MΩ" + Tolerances[Tolerance]; // Problem
        return z;
    }

    return "An error occured, please try again...\n";
}

The errors being thrown are:

error C3867: 'std::basic_istringstream<_Elem,_Traits,_Alloc>::str': function call missing argument list; use '&std::basic_istringstream<_Elem,_Traits,_Alloc>::str' to create a pointer to member

error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)

Thanks,
Jamie

lxXTaCoXxl 26 Posting Whiz in Training

I'm out of practice on my C++ and have kind of picked up a new hobby; it turns out that I like creating electronic devices. Particularly amplifiers and sound to light kits. Stuff like that; the problem is that determining the amount of resistance a resistor on an old creation that I'm pulling apart, or while studying someone else's work is troublesome to do on paper. The math is simple, but I'd like to create an application that can do it for me. That's why I picked up programming in the first place right? :D

Okay so here's the problem. I've created a class called Resistor and have set everything up as I should. However I'm getting a single problem (and am worried about another one occuring as soon as this one is fixed); I'm trying to create a member function that's called CalculateResistance with 4 arguments of type 'int' however the member function has to return a string and even though I've told the application to include 'string' it still tells me that 'string' is undefined.

The second problem that might occur would be one of implicit conversion. I'm unsure as to whether C++ allows this or not from 'string' to 'int' so that I get to perform the math correctly. Here is the source as well as an example of how to find the resistance of a resistor using the color coding on it.

#include <string>

class Resistor {
    public:
        Resistor();
        int Bands[10];
        int Multipliers[10];
        int Tolerances[3]; …
lxXTaCoXxl 26 Posting Whiz in Training

It's been a while since I've posted anything; I've been really busy. I was just sworn into the Marine Corps, and just finished making my own 5x5x5 LED cube. Now I'm wanting to get a little programatical with what I did in the real world. Basically I'm needing to find the real time volume of the computer. For example, when you have a song playing and click the sound icon on your taskbar it'll pop up a miniature window that has a green bar the is constantly moving to the volume from the song. Now I'm wanting to do something a little different than that but I need to know how to find that value first. I keep searching around google but the effort fails everytime. I'd appreciate some help on the matter.

Thanks,
Jamie

lxXTaCoXxl 26 Posting Whiz in Training

The problem seems to be that you're not initializing the Form; either that or Form1 is in another namespace by accident (highly unlikely but can happen). To resolve this try:

Form1 f1 = new Form1();
f1.Show();
Hope it helps,
Jamie
lxXTaCoXxl 26 Posting Whiz in Training

How are you measuring the speeds of the algorithms? I've been looking but can't find anything. I find the solutions you posted interesting. :)

See I would love some more acutal discussion threads on source code solutions. This is a must for me and my team. It allows other people to see the programming styles of other programmers and learn from them. It's always been a good thing to me. :D

lxXTaCoXxl 26 Posting Whiz in Training

I think this is the first actual discussion thread of code on a coder's website I've actually ever seen, and I'm the one posting it. (HA!) So basically; I got bored and found a website called Project Euler. It has a bunch of "mathematical" problems to solve. Eight pages and I believe 50 problems per page. Well I've been jumping back and forth between pages all day solving the problems out of boredom. Well, I came across this one and just had to share my work. It was the first time I've ever implemented the .Substring(int, int) method before so it gave me a little bit of problems at first, but I figured it out and got the answer. I'm deciding to share my source code as well as the answer to the problem. I just wanted to know other's thoughts on the topic and see if there is a way (which I'm sure there is) to shorten the source code, or even a completely different way of solving this problem.

The problem is: Find the highest product of 5 consecutive digits in the 1000 digit number.
Answer: 40,824 with 994 possible other answers, and the consecutive digits being 9,9,8,7,9.

Source:

            private string OneThousandDigitNumber = "7316717653133062491922511967442657474235534
            919493496983520312774506326239578318016984801869478851843858615607891129494954595017
            379583319528532088055111254069874715852386305071569329096329522744304355766896648950
            445244523161731856403098711121722383113622298934233803081353362766142828064444866452
            387493035890729629049156044077239071381051585930796086670172427121883998797908792274
            921901699720888093776657273330010533678812202354218097512545405947522435258490771167
            055601360483958644670632441572215539753697817977846174064955149290862569321978468622
            482839722413756570560574902614079729686524145351004748216637048440319989000889524345
            065854122758866688116427171479924442928230863465674813919123162824586178664583591245
            665294765456828489128831426076900422421902267105562632111110937054421750694165896040
            807198403850962455444362981230987879927244284909188845801561660979191338754992005240
            636899125607176060588611646710940507754100225698315520005593572972571636269561882670
            428252483600823257530420752963450";

            private void button1_Click(object sender, EventArgs e) {
                List<int> Possibles = new List<int>();
                List<string> Pos2 = new List<string>();

                for (int i = 0; i < OneThousandDigitNumber.Length - 5; i++) { …
lxXTaCoXxl 26 Posting Whiz in Training

@ddanbe Which would you perfer to see as an algorithim? I mean I can do them all but, if you had to choose one. :)

Multiplicative Inverse (Also known as Reciprocal)
Reciprocal of a Spiral
Reciprocal of a Polynomial

Sorry it took so long to get back to work on this, I got caught up in requested work. :)

lxXTaCoXxl 26 Posting Whiz in Training

Also change lines 106 and 111 to:

// 106:
return ToHex(ToDecimal(Address1) - ToDecimal(Offset.PadRight(8, '0')));

// 111:
return ToHex(ToDecimal(Address1) + ToDecimal(Offset.PadRight(8, '0')));
lxXTaCoXxl 26 Posting Whiz in Training

Well when working with XNA the Square class will either Derive from a base class (usually called GameplayObject) which would normally hold all the different values. But with someone that doesn't know polymorphism yet, they would put the velocity of the square, color, rotation presets, location, size (the last two there the rectangle class has), and to do some interesting new work styles you could simulate physics into a tetris clone like I did, granted I derived my class from the Rectangle class anyways; but not the point. My square class had extra variables, such as; mass, acceleration, gravitational constant, methods to determine the results of physical math, and even had some bounce animation going on using drag and a so called wind speed. There are a lot of interesting things you can do with games, that is only limited to what your mind can feed you for ideas. So a basic square class wouldn't have too many differences, but if the game is not an exact clone and the programmer is mixing it up a bit, then yes there can be a whole mess of differences. :)

lxXTaCoXxl 26 Posting Whiz in Training

Change data at line 3 to 0xffff; the 0xfffc is with the 2 lower bits dropped.

lxXTaCoXxl 26 Posting Whiz in Training

Figured I've been working on material for a while and would throw these up for everyone that needs them in the future to use. It's very simple implementation; if I get enough people asking me to, I will write the methods for each of the instructions so you don't have to do it yourselves. I know Jump and Link was hard enough for me. :)

Welcome,
Jamie

lxXTaCoXxl 26 Posting Whiz in Training

Also, for Square Root, Exponents, and so on, you'll have to perform the math in the same way I demonstrated; however there is one rule. You must perform the math on the number to be manipulated before performing the math on the manipulation. For example:

5 + 8 + SquareRoot(9). We know the answer to this is 16. Our computers know this as well, however they can't tell you the answer just by looking at SquareRoot(9). They need to be told how to calculate that. So for something involving manipulation of a number you would perform the math in steps. Shall I explain?

With my example 5 + 8 + SquareRoot(9) we would first solve 5 + 8, giving us 13. Then we would solve for the square root of 9; which brings out new expression to 13 + 3. Thus giving us the answer of 16. But say the user wants to make it 5 + 8 + SquareRoot(9) + 4, which is equal to 20. To do this, we would solve the Square Root of 9 before performing math on 13 + SquareRoot(9). Then we would perform the math. So using the same algorithms I provided earlier (switch logic) you would add in an extra button called SquareRoot (or whatever you want to call it) that would serve as a notice to perform Square Root math. Meaning you would add a new variable called (for example) SpecialMath as type boolean. Then if SpecialMath is a true value, see …

lxXTaCoXxl 26 Posting Whiz in Training

Well I thought about using a list, and all that fun stuff, but the guys over in the C# section helped me figure out my algorithm in C# and then I just converted it over to C++. Thanks for all the help.

lxXTaCoXxl 26 Posting Whiz in Training

True; we would derive from the Rectangle class, it's what I did. But I don't know if Lightning knows about Polymorphism or not. It's an advanced topic, and if he didn't know what the problem was with this error, then he's probably still a little new to programming, or at least this language. There's no problem with that of course, we all have to start somewhere.

lxXTaCoXxl 26 Posting Whiz in Training

Thanks, those where very helpful. :)

lxXTaCoXxl 26 Posting Whiz in Training

I did everything but fix the display string for you. The display string will keep adding the incorrect values, but the math stays correct. :)

Fix the display problem and you'll have a functioning calculator. :)

        private double Value1 = 0;
        private double Value2 = 0;

        private string Value2StringTemp = "";

        private int CurrentOp = 0;
        private int NextOp = 0;

        private void ButtonOne_Click(object sender, EventArgs e) {
            Value2StringTemp += "1";
            mathPerformed.Text += Value2StringTemp;
            Value2 = Convert.ToDouble(Value2StringTemp);

            CurrentOp = NextOp;
        }

        private void ButtonTwo_Click(object sender, EventArgs e) {
            Value2StringTemp += "2";
            mathPerformed.Text += Value2StringTemp;
            Value2 = Convert.ToDouble(Value2StringTemp);

            CurrentOp = NextOp;
        }

        private void ButtonPlus_Click(object sender, EventArgs e) {
            CurrentOp = CurrentOp == 0 ? 1 : CurrentOp;

            switch (CurrentOp) {
                case 1: Value1 += Value2; break;
                case 2: Value1 -= Value2; break;
                case 3: Value1 *= Value2; break;
                case 4: Value1 /= Value2; break;
            }

            NextOp = 1;

            Value2StringTemp = "";
            mathPerformed.Text += " + ";
            currentAnswer.Text = Value1.ToString();

            Value2 = 0;
        }

        private void ButtonMinus_Click(object sender, EventArgs e) {
            CurrentOp = CurrentOp == 0 ? 2 : CurrentOp;

            switch (CurrentOp) {
                case 1: Value1 += Value2; break;
                case 2: Value1 -= Value2; break;
                case 3: Value1 *= Value2; break;
                case 4: Value1 /= Value2; break;
            }

            NextOp = 2;

            Value2StringTemp = "";
            mathPerformed.Text += " - ";
            currentAnswer.Text = Value1.ToString();

            Value2 = 0;
        }

        private void ButtonDot_Click(object sender, EventArgs e) {
            Value2StringTemp += ".";
            mathPerformed.Text += Value2StringTemp;
            Value2 = Convert.ToDouble(Value2StringTemp);

            CurrentOp = NextOp;
        }

        private void ButtonEquals_Click(object …
lxXTaCoXxl 26 Posting Whiz in Training

Okay, reading over your source code there are a few things I can point out to you that you might be interested in for shortening the amount of line's you'll have overall.

1) Since you're requiring access to Form1 in Form2 you can create a variable of Form1 in Form2 then request it in the constructor; this would help with assigning the whole Form2.Form1 thing. Also to get rid of the conditional where you're checking to see if Form2 has been disposed or not, it's not required. Instead move your declaration of Form2 into the area where you're calling Form2.

        // Inside Form2.cs
        private Form1 MainForm;

        public Form2(Form1 f1)
        {
            this.MainForm = f1;
            InitializeComponent();
        }

        // Form1.cs:
        public partial class Form1 : Form
        {
            /* Form2 frm2 = new Form2(); -- Remove this. */
            public Form1() {
                InitializeComponent();
            }

            public string getTextButton() {
                return callform2.Text;
            }

            private void callform2_Click(object sender, EventArgs e) {
                Form2 f2 = new Form2(this);
                f2.Show();
            }

That will ensure that Form2 is never disposed when called since you're only calling it from there. You can just declare, initialize, and use it from the method you're calling it in.

2) You can get rid of 'if', 'else if', 'else' on the 'opmode' variable and use switch structure. If you're unfamiliar with switch structure below is an example using your variable:

    switch (opmode) {
        case 0: doSomething(); break;
        case 1: doSomethingElse(); break;
        case 2: doSomethingDifferent(); break;
    }

3) When performing math of …

lxXTaCoXxl 26 Posting Whiz in Training

LOL @skatamatic I was just waiting on your reply, and the people over in the C++ section said to use a struct. But I couldn't "completely" understand the sample they gave because I'm still a little new to C++. However, I like the example you gave, and can at least understand it partially. Could you do me a solid and explain how the 'from' structure you have there is working? I don't completely think I understand the 'let' and select' keywords. From just reading the example it looks like it's creating a new temporary variable called 'tempExponent' then setting the value to the exponent minus the result of a conditional (one or zero). Then as for the select keyword, I have now idea what it is doing. Also, is the structure compatible with C++? Thanks again for the help.

lxXTaCoXxl 26 Posting Whiz in Training

Thanks anyways, I had some help but figured it out. :)

lxXTaCoXxl 26 Posting Whiz in Training

A pong game requires (like any other game) planning. Even though it is the simplest game to write, it can be frustrating if you don't aquire knowledge on how the game works. I know, I know, you're thinking what more can be to it than just the ball moving around, and two paddles hitting it back and forth? Well there are a lot of dynamics in the game that simple developers would realize, and sometimes even advanced developers look over it.

Basically there a few things you will need for each object in the game:
Player: Location, Sprite, MoveSpeed, Score
Computer: Location, Sprite, MoveSpeed, Score, BallLocation, DistanceDetection (usually a float value for pixels)
Ball: Location, Sprite, MoveSpeed, Velocity

General: Screen Width, Screen Height, Player/Computer Sprite Widths

The workings of the player is very simple. If the player inputs the button or key (or other action) to move up or down, we simulate the paddle doing so. So for example in pseudocode:

// Psuedocode (C++ Syntax):
const int MoveSpeed = 5;
VectorVariableType Location;

const int ScreenWidth = 0;
const int ScreenHeight = 0;

// Update player movement:
Location.Y += MoveUpCondition ? -5 : 5;

With the computer we would just detect how far away the ball is to see if we should move the paddle to try and hit it. So in pseudocode:

// Pseudocode (C++ Syntax):
VectorVariableType Location;

BallVariable Ball;

const int ScreenWidth = 0;
const int ScreenHeight = 0;

const float DetectionDistance = 100f;

// …
lxXTaCoXxl 26 Posting Whiz in Training

I'm writing a basic application that needs to know the mathematical relationship between a jal and its address. For example:

jal $000a2000 = 0x0c028800

So my question is how would I get this value mathematically? I've been pondering ways to do it all week and every route I took to re-construct the jal to address relationship was futile. Any help would be appreciated. Also if it has anything to do with the jal's opcode than can someone also include how the opcode registers and constants relate mathematically? For example:

addui t0, t1, $0001 = 0x24020001

Thanks,
Jamie

P.S. :: The hex outputs are estimated guesses as to what I remember the hex data to be, I didn't boot up my assembler to find out for sure what the values actually were.

lxXTaCoXxl 26 Posting Whiz in Training

Create a for loop that will evaluate each card in the hand using switch logic. For example:

int[] ThreeOfAKind = new int[3];

for (int i = 0; i < 3; i++) {
    for (int x = 0; x < 7; x++) {
        if (i >= 1)
            ThreeOfAKind[i] = ThreeOfAKind[i - 1] + 1 == hand[i] ? hand[i] : 0;

        else
            ThreeOfAKind[i] = hand[i];
    }
}

// or

for (int i = 0; i < 7; i++) {
    switch (hand[i]) {
        case 0: /* do something */ break;
    }
}

The first example would be a little buggy and needs tweaking but it's just pseudocode. You should read each card in the hand and determine if there are 3 in ascending order. Use a multi-dimensional array or something to read each. But as @Clinton Portis stated, you should build some functions to do your bidding for you. Create a card class, a deck class, and then in the main thread run all the game logic dealing with each.

lxXTaCoXxl 26 Posting Whiz in Training

Two things:

1) I love your signature it's completely true.
2) How would I just allow the user to input the polynomial as they would write it in notepad: 3x^3 + 13x + 4 for example. The whole process of inputing each one by hand takes a while, but I suppose is a good way to solve it. I did enjoy your approach on the idea. I'll try implementing it and let you know what happens. However, what is line 14 doing? I don't see any data being stored to numPolynomials, and have no experience with the sizeof keyword. Based on it's name I'm guessing it's something to do with the value it holds and setting a variable up as an array style variable. That's what it looks like to me anyways. Also, if I remember correctly (not sure) but isn't * a pointer operator? Just needing some explinations on those before I can get started. :)

Thanks for the help,
Jamie

lxXTaCoXxl 26 Posting Whiz in Training

For example? LOL

I knew that I should use a list, but the problem is how do I read each one as part of each polynomial:

// Pseudocode:
private string DerivativeOfPolynomial(int[] Bases, string[] Variables, int[] Exponents) {
    string temp = "";
    for (int i = 0; i < Bases.Length; i++) {
        Bases *= Exponents[i] >= 1 ? Exponents[i] : 1;
        Exponents[i] -= Exponents[i] > 1 ? 1 : 0;
        string exTemp = Exponents[i] == 0 ? "" : Exponents[i].ToString();
        Variables[i] = Exponents[i] > 1 ? Variables[i] + "^" : "";

        temp += Bases.ToString() + Variables[i] + exTemp + " :: ";
    }

    return temp;
}

However if all three array lengths are not the same either an exception will be thrown for index out of bounds or not all terms will be simplified.

lxXTaCoXxl 26 Posting Whiz in Training

Square is defined again inside of another .cs file and needs to be renamed. Although, if you're writing this with XNA you should really switch your project type over to Windows Game type.

@Momerath: When designing games it's good practice to create your own objects, plus the Rectangle class inside of System.Drawing is meant for many purposes, but does not have all the variables that a square in a Tetris clone would have.

lxXTaCoXxl 26 Posting Whiz in Training

In the solution explorer of Visual Studio (which ever edition you might have) there should be a folder called YourProjectNameHere Conent. Right click that folder and choose Add->Existing item. Then to load the .png or .bmp you would call Content.Load<Texture2D>("textureName"); and assign it to the Texture2D variable. For example, say my project name is RandomProjectTest. In the solution explorer there will be a folder that's called RandomProjectTestContent (Content), you can right click it and choose Add->Existing Item or you can left click it, and then just press Shift + Alt + A on your keyboard to do the same thing. Then to load the texture:

Texture2D MyTexture;

        protected override void LoadContent() {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the texture:
            MyTexture = Content.Load<Texture2D>("textureName");
        }

Now if you create folders within the Content area you will have to specify which folder the texture is in, if it's sitting outside of Content's sub-folders that's fine. But say you create a folder in the Content folder called MyFolder and then you put your texture called MyTexture inside of that folder. You would have to load it specifying exactly where the texture is:

Texture2D MyTexture;

        protected override void LoadContent() {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the texture:
            MyTexture = Content.Load<Texture2D>("MyFolder/MyTexture");
        }

Hope I helped a little more. Feel free to private message me if you need me because I get an email everytime you do. :)

lxXTaCoXxl 26 Posting Whiz in Training

I'm trying to upgrade my class library to my current mathematical skill set and am having trouble with multi-term polynomials, especially those I where I don't know how many terms the user will be putting in. I know that the formula for the first derivative of a polynomial is ax^n = n * ax^n-1; and the second derivative is the derivative of the first derivative. So for example:

Find the derivative of 4x^2:
4x^2 = 2 * 4x^2 - 1 = 8x^2-1 = 8x

Find the second derivative of 4x^3:
4x^3 = 3 * 4x^3-1 = 12x^3-1 = 12x^2
12x^2 = 2 * 12x^2-1 = 24x^2-1 = 24x

Right now I just have an algorithm for the first derivative of a single term polynomial:

    // Pesudocode (C++ Syntax):
    int Base = 0;
    int Exponent = 0;
    string Variable = "";

    cout << "Please input a polynomial to the first degree in the form (4 y 9): ";
    cin >> Base >> Variable >> Exponent;

    Base = Exponent * Base;
    Exponent = Exponent > 1 ? Exponent - 1 : 0;
    Variable = Exponent == 1 ? Variable : Variable + "^";
    Variable = Exponent == 0 ? "" : Variable;
    string exString = (Exponent == 1 || Exponent == 0) ? "" : (const char*)Exponent;

    cout << "The first derivative of the polynomial you submited is: " << Base << Variable << exString << "\n";

Chose to not work on the second derivatives until …

lxXTaCoXxl 26 Posting Whiz in Training

I'm trying to upgrade my class library to my current mathematical skill set and am having trouble with multi-term polynomials, especially those I where I don't know how many terms the user will be putting in. I know that the formula for the first derivative of a polynomial is ax^n = n * ax^n-1; and the second derivative is the derivative of the first derivative. So for example:

Find the derivative of 4x^2:
4x^2 = 2 * 4x^2 - 1 = 8x^2-1 = 8x

Find the second derivative of 4x^3:
4x^3 = 3 * 4x^3-1 = 12x^3-1 = 12x^2
12x^2 = 2 * 12x^2-1 = 24x^2-1 = 24x

Right now I just have an algorithm for the first derivative of a single term polynomial:

// Pseudocode (C# Syntax):
public string DerivativeOfPolynomial(int Base, string Variable, int Exponent) {
    Base = Exponent * Base;
    Exponent = Exponent > 1 ? Exponent - 1 : 0;
    Variable = Exponent == 0 ? "" : Variable;

    return Base.ToString() + Variable + (Exponent == 0 ? "" : Exponent).ToString();
}

Chose to not work on the second derivatives until I figure out the whole parameter problem. I'm sure I have to use arrays or lists to accomplish this, but I'm not sure how the algorithm would work for a polynomial with 3 terms:

3x^2 + 13x + 4

Also the derivative of a constant (basically any number without a variable and exponent of 2 or higher) is equal to 0 for those who don't know.

lxXTaCoXxl 26 Posting Whiz in Training

I agree with @skatamatic on this topic. If you must write a Tetris clone then start by learning the framework. You'll need to know how to load Textures (I use PNG but BMP works just as well) then you'll need to learn how to manipulate the texture (using keyboard and or game pad input, or if you have the Kinect SDK you can set it up for Kinect), drawing the textures to the screen, drawing strings to represent things like score, combo, etc. A lot of work comes with XNA development because we have to do everything on our own. There is no form designer. :D

Your work is only limited by your imagination; but before you begin writing a big game (fps, rpg, 3ps, etc) get in the habbit of laying everything out in a flow chart. You'll want that organization later on, when you get stuck on something, leave the project for a week, and come back not knowing what all is left to do; or sometimes even what you wanted to do.

**Note **
If you're reading this and are learning about 3D game design then in that case we do have a form designer: UDK :D It's perfect for creating 3D environments before sending them to the game. I wrote a nifty little app that "seeds" the environments straight to the live debugger of XNA allowing me to add in characters and everything and test the look through the game without all the big tools …

lxXTaCoXxl 26 Posting Whiz in Training

Yes; and as @thines01 stated, if you are looking for perfect numbers then the formula would be completely different.

lxXTaCoXxl 26 Posting Whiz in Training

First you must tell the computer how to calculate a perfect number, if I remember correctly you're meaning prime which simply means it's only divisible by itself and 1. So create a list of integers then add each prime as it finds it. Hope it helps.

List<int> Primes = new List<int>();

for (double d1 = 0; d1 < 10000; d1++) {
    if (ConditionMet)
        Primes.Add(d1);
}
lxXTaCoXxl 26 Posting Whiz in Training

Try removing the try catch block:

private void linkLabel1_Click(object sender, LinkLabelLinkClickedEventArgs e) {
    Process.Start("http://www.website.com");
    linkLabel1.LinkVisited = true;
}

If that doesn't work then switch over the event to the simple clicked event:

linkLabel1.Click += new EventHandler(linkLabel1_Click);

private void linkLabel1_Click(object sender, EventArgs e) {
    Process.Start("http://www.website.com");
    linkLabel1.LinkVisited = true;
}

It's probably going to have to be switched over to the standard click event.

lxXTaCoXxl 26 Posting Whiz in Training

I found the problem, and it actually was not with the operators. It was in the constructor for the HexAddress class. The problem was that it was actually changing the values using the method ReplaceWriteMode that replaces the first character in the string with a zero. I have it working perfectly now. Thanks anyways!

Jamie

lxXTaCoXxl 26 Posting Whiz in Training

I get tired of having to google this simple line of code all the time. My problem with memorizing it is that I switch back and forth between C# and C++ all the time, and the way you overload operators in each is different. So once I learn one again, I forget the other... >_< No fun lol.

Anyways I figure this will be useful for anyone else out there that needs to know how to overload operators with custom user types. For example using a vector style user type:

public static TriVector operator +(TriVector o1, TriVector o2) {
    return new TriVector(o1.X + o2.X, o1.Y + o2.Y, o1.Z + o2.Z);
}

Hope it helps some others as well.