Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Ta-183

Pages: [1]
1
Off Topic / My first C++ Program
« on: July 23, 2009, 01:53:02 PM »
As a few of you know, I'm taking courses on programming in C++ at the community college while I'm still in high school (with a crazy mother of a discount, $40 a class!) and I've always had a bit of an interest in a certain programming 'sport', if you will, that was played back around a decade ago. Competitive rock paper scissors. Programmers build bots that go against one another for god knows how many rounds and use a sophisticated ranking system to see who wins. Some of the systems that were developed were out of this freaking world, including some incredible behavioral analysis routines that were just about spot on. About six months ago, I had implemented my own version of such a sport in TI-BASIC on my TI-84. I lost said systems to a random RAM reset (and was VERY pissed off). Now, I've finished my first program in C++ that I've built myself from the bottom up, and replicated an early version of my main bot. If any of you guys know your C++, please take a look over my source code. Comments and criticism are welcomed. It doesn't use any funky libraries, so just about any compiler will launch it pretty quickly. If you have no compiler, I've included the executable for those who just wanna dink around with it.

[code]//Rock-Paper-Scissors v1.1.1
//By Ta-183
//Written in C++ in Bloodshed Dev-C++ 4.9.9.2 IDE

#include <iostream>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int computerRESP(int, int, int[3][99]);
int computerRARAY(int, int, int[3][99]);
int computerRAND();
int humanPlayer();
int main()
{
    int player1 = 0;
    int player2 = 0;
    int p1mode = 0;
    int p2mode = 0;
    int win = 0;
    int fail = 0;
    int draw = 0;
    int count = 0;
    int exit = 0;
    int mode = 0;
    char displog = ' ';
    int logArray[3][99] = {0};
    int rounds = 0;
    //NOTE; Row 0 is win/loss logging. 1=player 1 win, 2=player 2 win, 3=tie
    //Row 1 Is player 1 logging. Same selection scheme as rest of program.
    //Row 2 is player 2 logging.
    // 1 = Rock, 2 = Paper, 3 = Scissors
    //Vaguely considering switching to a string array. Interger based logging is a holdover from my experience using TI-BASIC.

    const int mintypes = 1;
    const int maxtypes = 4;
    srand(int(time(0)));

    do
    {
        cout << "\nSelect Player 1 control.";
        cout << "\n1. Human Player";
        cout << "\n2. Computer (Random Generator)";
        cout << "\n3. Computer (Counter Bot)";
        cout << "\n4. Computer (ResponderC++)\nPlayer 1: ";
        cin >> p1mode;
        if (p1mode < mintypes || p1mode > maxtypes)
        {
                   cout << "\n\nThe valid choices are " << mintypes << " through " << maxtypes << ".\n\n";
        }
    } while (p1mode < mintypes || p1mode > maxtypes);
      do
    {
        cout << "\nSelect Player 2 control.";
        cout << "\n1. Human Player";
        cout << "\n2. Computer (Random Generator)";
        cout << "\n3. Computer (Counter Bot)";
        cout << "\n4. Computer (ResponderC++)\nPlayer 2: ";
        cin >> p2mode;
        if (p2mode < mintypes || p2mode > maxtypes)
        {
                   cout << "\n\nThe valid choices are " << mintypes << " through " << maxtypes << ".\n\n";
        }
    } while (p2mode < mintypes || p2mode > maxtypes);
    do
    {
        cout << "\n\nEnter number of rounds to be played. (Must be between 1 and 99)\nNumber of rounds: ";
        cin >> rounds;
        if (rounds < 1 || rounds > 99)
        {
                   cout << "\nThe number of rounds must be between 1 and 99.";
        }
    } while (rounds < 1 || rounds > 99);

    for (int count = 0; count <= (rounds - 1); count = count + 1)
    {
        mode = 1;
        switch (p1mode)
        {
               case 1: player1 = humanPlayer();
               break;
               case 2: player1 = computerRAND();
               break;
               case 3: player1 = computerRARAY(mode, count, logArray);
               break;
               case 4: player1 = computerRESP(mode, count, logArray);
               break;
        }

        mode = 2;
        switch (p2mode)
        {
               case 1: player2 = humanPlayer();
               break;
               case 2: player2 = computerRAND();
               break;
               case 3: player2 = computerRARAY(mode, count, logArray);
               break;
               case 4: player2 = computerRESP(mode, count, logArray);
               break;
        }      
            if ((player1 == 1 && player2 ==2) || (player1 == 2 && player2 == 3) || (player1 == 3 && player2 == 1))
            {
                 fail = fail + 1;
                 logArray[0][count] = 2;
                 logArray[1][count] = player1;
                 logArray[2][count] = player2;
            }
            else if ((player1 == 2 && player2 ==1) || (player1 == 3 && player2 == 2) || (player1 == 1 && player2 == 3))
            {
                 win = win + 1;
                 logArray[0][count] = 1;
                 logArray[1][count] = player1;
                 logArray[2][count] = player2;
            }
            else if (player1 == player2)
            {
                 draw = draw + 1;
                 logArray[0][count] = 3;
                 logArray[1][count] = player1;
                 logArray[2][count] = player2;
            }//End ifs
            //Text output for human players
            if (p1mode == 1 || p2mode == 1)
            {
                switch (player1)
                {
                       case 1: cout << "\nPlayer 1 chose Rock.";
                       break;
                       case 2: cout << "\nPlayer 1 chose Paper.";
                       break;
                       case 3: cout << "\nPlayer 1 chose Scissors.";
                       break;
                }//End Switch
                switch (player2)
                {
                       case 1: cout << "\nPlayer 2 chose Rock.";
                       break;
                       case 2: cout << "\nPlayer 2 chose Paper.";
                       break;
                       case 3: cout << "\nPlayer 2 chose Scissors.";
                       break;
                } //End Switch
                switch (logArray[0][count])
                {
                       case 1: cout << "\nPlayer 1 Wins!\n";
                       break;
                       case 2: cout << "\nPlayer 2 Wins!\n";
                       break;
                       case 3: cout << "\nDraw!\n";
                       break;
                }//End Switch
            }//End if
        player1 = 0;
     } //endfor
     cout <<"\n\n------ENDGAME------";
     cout << "\nPlayer 1: " << win << endl << "Player 2: " << fail << endl << "Draw: " << draw;
     cout << "\n\nDisplay game log? Y/N: ";
     cin >> displog;
     //Begin Endgame Log Display
     while (displog == 'y' || displog == 'Y')
     {
           cout << "\nRound   Player 1   Player 2   Result\n";
           for (int count = 0; count <= (rounds - 1); count = count + 1)
           {
               cout << endl;
               //Slight aesthetic fix, makes output ine up better.
               if (count <= 8)
               {
                         cout << "0";
               }
               cout << (count + 1) << ":     ";
               switch (logArray[1][count])
               {
                      case 1: cout << "rock       ";
                      break;
                      case 2: cout << "paper      ";
                      break;
                      case 3: cout << "scissors   ";
                      break;
                      default: cout << "ERROR      ";
                      break;
               }
               switch (logArray[2][count])
               {
                      case 1: cout << "rock       ";
                      break;
                      case 2: cout << "paper      ";
                      break;
                      case 3: cout << "scissors   ";
                      break;
                      default: cout << "ERROR      ";
               }
               switch (logArray[0][count])
               {
                      case 1: cout << "P1 Wins";
                      break;
                      case 2: cout << "P2 Wins";
                      break;
                      case 3: cout << "Draw";
                      break;
               }
           } //End for
           displog = ' ';
     } //End While
     cout << "\n\nEnter 1 to end program.";
     cin >> exit;
     return 0;
}//end of main

//------------------------------------------------------------------------------------------
//------------------------------------------------------------ResponderC++ v1.1
//------------------------------------------------------------------------------------------
//Complete rebuild of ResponderTI in C++.
//Does not require or utilize the complicated addons and equipment routines that ResponderTI used.
int computerRESP(int posit, int turn, int movelog[][99])
{
    //Initialize internal variables
    int internCounterRES = 0;
    double didntwinRES = 0.0;
    int lpincRES = 0;
    int listCounterRES = 0;
    int nmeLastMoveRES = 0;
    int myLastMoveRES = 0;
    int myMoveRES = 0;
    int rockResponseRES = 0;
    int paperResponseRES = 0;
    int scissorsResponseRES = 0;
    int highAvgRES = 0;
    //Begin Responder code ------(Position 1)------
    if (posit == 1 && turn >= 2)
    {
              myLastMoveRES = movelog[1][turn - 1];
    //Begin Average Response Computation
    //Responses to 'Rock'
              if (movelog[1][turn - 1] == 1)
              {
                      //Loop for average responses
                      for (internCounterRES = 0; internCounterRES <= (turn - 1); internCounterRES = internCounterRES + 1)
                      {
                            if (movelog[1][internCounterRES] == 1)
                            {
                                    switch (movelog[2][(internCounterRES + 1)])
                                    {
                                           case 1: rockResponseRES = rockResponseRES + 1;
                                           break;
                                           case 2: paperResponseRES = paperResponseRES + 1;
                                           break;
                                           case 3: scissorsResponseRES = scissorsResponseRES + 1;
                                           break;
                                    }//End switch
                            }//End if
                      }//End for
                      //Find most common response
                      if (rockResponseRES >= paperResponseRES && rockResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 1;
                      }
                      else if (paperResponseRES >= rockResponseRES && paperResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 2;
                      }
                      else if (scissorsResponseRES >= rockResponseRES && scissorsResponseRES >= paperResponseRES)
                      {
                            highAvgRES = 3;
                      }//End ifs
              }//End if
              //End Rock responses
    //Responses to 'Paper'
              if (movelog[1][turn - 1] == 2)
              {
                      //Loop for average responses
                      for (internCounterRES = 0; internCounterRES <= (turn - 1); internCounterRES = internCounterRES + 1)
                      {
                            if (movelog[1][internCounterRES] == 2)
                            {
                                    switch (movelog[2][(internCounterRES + 1)])
                                    {
                                           case 1: rockResponseRES = rockResponseRES + 1;
                                           break;
                                           case 2: paperResponseRES = paperResponseRES + 1;
                                           break;
                                           case 3: scissorsResponseRES = scissorsResponseRES + 1;
                                           break;
                                    }//End switch
                            }//End if
                      }//End for
                      //Find most common response
                      if (rockResponseRES >= paperResponseRES && rockResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 1;
                      }
                      else if (paperResponseRES >= rockResponseRES && paperResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 2;
                      }
                      else if (scissorsResponseRES >= rockResponseRES && scissorsResponseRES >= paperResponseRES)
                      {
                            highAvgRES = 3;
                      }//End ifs
              }//End if
              //End Paper responses
    //Responses to 'Scissors'
              if (movelog[1][turn - 1] == 3)
              {
                      //Loop for average responses
                      for (internCounterRES = 0; internCounterRES <= (turn - 1); internCounterRES = internCounterRES + 1)
                      {
                            if (movelog[1][internCounterRES] == 3)
                            {
                                    switch (movelog[2][(internCounterRES + 1)])
                                    {
                                           case 1: rockResponseRES = rockResponseRES + 1;
                                           break;
                                           case 2: paperResponseRES = paperResponseRES + 1;
                                           break;
                                           case 3: scissorsResponseRES = scissorsResponseRES + 1;
                                           break;
                                    }//End switch
                            }//End if
                      }//End for
                      //Find most common response
                      if (rockResponseRES >= paperResponseRES && rockResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 1;
                      }
                      else if (paperResponseRES >= rockResponseRES && paperResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 2;
                      }
                      else if (scissorsResponseRES >= rockResponseRES && scissorsResponseRES >= paperResponseRES)
                      {
                            highAvgRES = 3;
                      }//End ifs
              }//End if
              //End Scissors responses
    }//End if
    //End Position 1 Responder code
//Begin Responder code ------(Position 2)------
    if (posit == 2 && turn >= 2)
    {
              myLastMoveRES = movelog[2][turn - 1];
    //Begin Average Response Computation
    //Responses to 'Rock'
              if (movelog[2][turn - 1] == 1)
              {
                      //Loop for average responses
                      for (internCounterRES = 0; internCounterRES <= (turn - 1); internCounterRES = internCounterRES + 1)
                      {
                            if (movelog[2][internCounterRES] == 1)
                            {
                                    switch (movelog[1][(internCounterRES + 1)])
                                    {
                                           case 1: rockResponseRES = rockResponseRES + 1;
                                           break;
                                           case 2: paperResponseRES = paperResponseRES + 1;
                                           break;
                                           case 3: scissorsResponseRES = scissorsResponseRES + 1;
                                           break;
                                    }//End switch
                            }//End if
                      }//End for
                      //Find most common response
                      if (rockResponseRES >= paperResponseRES && rockResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 1;
                      }
                      else if (paperResponseRES >= rockResponseRES && paperResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 2;
                      }
                      else if (scissorsResponseRES >= rockResponseRES && scissorsResponseRES >= paperResponseRES)
                      {
                            highAvgRES = 3;
                      }//End ifs
              }//End if
              //End Rock responses
    //Responses to 'Paper'
              if (movelog[2][turn - 1] == 2)
              {
                      //Loop for average responses
                      for (internCounterRES = 0; internCounterRES <= (turn - 1); internCounterRES = internCounterRES + 1)
                      {
                            if (movelog[2][internCounterRES] == 2)
                            {
                                    switch (movelog[1][(internCounterRES + 1)])
                                    {
                                           case 1: rockResponseRES = rockResponseRES + 1;
                                           break;
                                           case 2: paperResponseRES = paperResponseRES + 1;
                                           break;
                                           case 3: scissorsResponseRES = scissorsResponseRES + 1;
                                           break;
                                    }//End switch
                            }//End if
                      }//End for
                      //Find most common response
                      if (rockResponseRES >= paperResponseRES && rockResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 1;
                      }
                      else if (paperResponseRES >= rockResponseRES && paperResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 2;
                      }
                      else if (scissorsResponseRES >= rockResponseRES && scissorsResponseRES >= paperResponseRES)
                      {
                            highAvgRES = 3;
                      }//End ifs
              }//End if
              //End Paper responses
    //Responses to 'Scissors'
              if (movelog[2][turn - 1] == 3)
              {
                      //Loop for average responses
                      for (internCounterRES = 0; internCounterRES <= (turn - 1); internCounterRES = internCounterRES + 1)
                      {
                            if (movelog[2][internCounterRES] == 3)
                            {
                                    switch (movelog[1][(internCounterRES + 1)])
                                    {
                                           case 1: rockResponseRES = rockResponseRES + 1;
                                           break;
                                           case 2: paperResponseRES = paperResponseRES + 1;
                                           break;
                                           case 3: scissorsResponseRES = scissorsResponseRES + 1;
                                           break;
                                    }//End switch
                            }//End if
                      }//End for
                      //Find most common response
                      if (rockResponseRES >= paperResponseRES && rockResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 1;
                      }
                      else if (paperResponseRES >= rockResponseRES && paperResponseRES >= scissorsResponseRES)
                      {
                            highAvgRES = 2;
                      }
                      else if (scissorsResponseRES >= rockResponseRES && scissorsResponseRES >= paperResponseRES)
                      {
                            highAvgRES = 3;
                      }//End ifs
              }//End if
              //End Scissors responses
 

2
F3 bots / Slam_Funk2.1(F3)(Ta-183)-5.27.09
« on: May 27, 2009, 08:09:48 PM »
ROBOT TOO BIG TO FIT!

Here you go guys, as promised. I got it to beat Beholder, and once it did, it shot to the top 5. (With a little hitch at Alpha..... You can just ignore the results of that match. It beats it... Sometimes.....)

3
Bugs and fixes / Leagues won't run new challengers 2.43L/M
« on: May 12, 2009, 11:07:44 PM »
No matter what version of 2.43 I use, league fights ALWAYS go top-down starting with the first two bots. I do everything right, I set it up correctly, physics and costs are set to F1 defaults, and I can't get it to work. This is a BIG problem, since I'm working on some improvements to one of my bots, and I need to see how things are going. I'd HATE to have to run this manually.

4
F3 bots / Slam_Funk2.0(F3)(Ta-183)-4.26.09
« on: April 26, 2009, 01:45:58 PM »
ROBOT TOO BIG TO FIT!

After sitting on these bots for about a month, I decided I'd finish them today. I can't really see EXACTLY how well this one is doing in the leagues (computer haet league) but I figured that since it's pretty near complete and it seems to run fine, it's ready to be released. Fell free to edit it for errors and tweak the numbers, I haven't been able to do so very well. Have fun with it guys, run it in the leagues next chance you get.

5
F3 bots / Slam_Funk1.1(F3)(Ta-183)-4.26.09
« on: April 26, 2009, 01:38:28 PM »
ROBOT TOO BIG TO FIT!

I'm happy (somewhat) to be able to release the updated and fully F3-compliant version of Slam funk, version 1.1. I have removed ALL non-F3 functions and redone a bit of the code. It might not be all too effective, or particularly well-tuned, feel free to fuddle with it. I'd tune it myself, but this computer doesn't seem to like running leagues right now. So, I'm releasing it.

6
Untagged bots / Slam Funk 1.0
« on: March 26, 2009, 10:41:34 PM »
Here's my first bot. It uses very simple genes with basic defenses. It's best features are it's group following behavior and it's vision system, with conspec embedded. If it spots a friendly in eye5, it follows. If it spots a bogey anywhere, it breaks off to feed. Has some slime, poison and shell, and I put in an ass-gun after a bad experience with a simple swarmer as a test. Has rudimentary antivirus.

Code: [Select]
'Slam Funk 1.0
'Uses simple genes and a simple conspec
'To survive at least against low level bots.
'Heavily based on Animal Minimalis,
'While very little of it was actually used.
'Best feature includes a very good vision system.
'It is able to follow its friends and break off to feed.

'Raises number of .eyeX commands to make a slightly more secure conspec.
cond
start
.eye5 .eye5 .eye5 .eye5 add add add add dup sub
stop

'Body storage gene.
cond
*.nrg 15000 >
*.body 500 < and
start
500 .strbody
stop

'See nothing, start looking. I wasn't content to just have it spin.
cond
*eye5 0 =
*.up 0 = and
start
20 .up store
stop

'Theres strength in numbers. This gene makes bots follow one another if they see a fellow

bot.
cond
*.eye5 0 >
*.refeye *.myeye =
start
*.refveldx .dx store
*.refvelUp .up store
30 .aimdx store
stop

'Targeting genes. If it spots food, it turns to it.

cond
start
-1 .focuseye store
stop

'Eye4
cond
*.eye4 0 !=
*.refeye *.myeye != and
start
5 .aimsx store
stop

cond
start
1 .focuseye store
stop

'Eye6
cond
*.eye6 0 !=
*.refeye *.myeye != and
start
-5 .aimsx store
stop

cond
start
-2 .focuseye store
stop

'Eye3
cond
*.eye3 0 !=
*.refeye *.myeye != and
start
15 .aimsx store
stop

cond
start
2 .focuseye store
stop

'Eye7
cond
*.eye7 0 !=
*.refeye *.myeye != and
start
-15 .aimsx store
stop

cond
start
-3 .focuseye store
stop

'Eye2
cond
*.eye2 0 !=
*.refeye *.myeye != and
start
35 .aimsx store
stop

cond
start
3 .focuseye store
stop

'Eye8
cond
*.eye8 0 !=
*.refeye *.myeye != and
start
-35 .aimsx store
stop

cond
start
-4 .focuseye store
stop

'Eye1
cond
*.eye1 0 !=
*.refeye *.myeye != and
start
40 .aimsx store
stop


cond
start
4 .focuseye store
stop

'Eye9
cond
*.eye9 0 !=
*.refeye *.myeye != and
start
-40 .aimsx store
stop

cond
start
0 .focuseye store
stop


'Ass-shot gene. Tested it against basicswarmer, swarmers beat the snot out of my bots by

following them close behind so I stuck this in here.
cond
*.shflav 0 !=
*.shflav -2 !=
start
1256 *.shang sub .aimshoot store
8 .shootval store
-6 .shoot store
0 .shflav store
stop



'The shooting gene. It fires if the bot sighted fails the conspec check and is in range.
cond
*.eye5 40 >
*.refeye *.myeye != and
start
8 .shootval store
-6 .shoot store
*.refvelup .up store
stop

'Reproduction gene. Gotta make mo' bots.
cond
*.body 500 >
start
40 .repro store
314 .aimdx store
stop

'Poison gene, because dying sucks.
cond
 *.nrg 10000 >
 *.poison 500 < and
start
 50 .strpoison store
stop

'Shell is good. This gene creates shell.
cond
 *.nrg 10000 >
 *.shell 250 < and
start
 100 .mkshell store
stop


'Slime gene, just in case.
cond
 *.nrg 10000 >
 *.slime 300 < and
start
 100 .mkslime store
stop

'Obligatory anti-viral gene
cond
 *.mkvirus 0 !=
start
 *.mkvirus .delgene store
stop


end

7
DNA - General / Multi-Eye targeting
« on: March 26, 2009, 08:22:34 PM »
I'm kind of miffed about my first bot (still a work in progress) having a very narrow effective sight radius. It uses .eye5 for conspec recognition, shooting, and following friendlies for a short amount of time (seems to be the bot's main feature). But I need to use a gene that will make it turn if it sees food in the other eyes. Eye5 is the only one used so far, and all widths are regular. Any help?

8
Bot Tavern / MB's and other Behaviors
« on: November 27, 2008, 08:11:48 PM »
First off, I barely know anything about DNA code, so I can't do any of this myself. However, many of these ideas can be accomplished by crude gene splicing (copy paste, with a few alterations).

1. Fractal defensive shield
After messing around with Fractals, and the other bots in that thread, I got one type of bot to put out what looked like a comet, curving outward and down. I then realize that this could be used as some sort of defense (given that the fractal was started with a very small percentage of the parent's energy) or simply a countermeasure to superior eyesight. For example, if the bot is hit, and puts its view to max and still detects no non-friendlies, put up the fractal shield in the direction of fire, and run like hell. Could also be used as an attack (if the bots energy is high enough for this to be acceptable) against a small number of enemy bots.

2. Biological tie attack missiles
My brother, De-Maskus, was messing with Alga Minimalis giving it two alterations that were first noticed in someones evosim that enabled the Alga to move using child bots as, literally, jet engines. Depending on the energy level of the bot (and HEAVILY depending on the friction settings) some of these 'nacelles' would shoot forward at high speed. They looked remarkably like missiles, and seemed to not require very much energy at all to fire. My idea was, coupled with some sort of long range spotting (may be available in a large MB or some sort of hive bot) these 'missiles' could be purposely created and fired at an organism, and when they get close, either tie attack or fire instakill shots, or a nasty virus. (Forced cancer, anyone?)

3. Fractal MultiBots
Ever since 'Fractals' was created, we've all wanted to see an effective multibot made from it. Combining it with some sort of movement routines, and hopefully some kind of defense or harvesting routines, may yield a crude yet interesting bot. If anyone who is experienced with DNA has the time, I would really appreciate it if someone could inject either Fractals or an existing MB with the code from either, we may have the workings of a neat MB. Combine these genes with swarming functions, and maybe write the code with PyBot or that other thing, we may have the neatest bot made in a while.

Pages: [1]