Rocks Papers Scissors always picks rocks

I wrote a Rocks papers Scissors game with an assumption that
-when the opponent wins the last game, he uses the same move the next game
-when the opponent looses the last game, he chooses the weaopen which would have defeated the computer in previous game.

Dumb assumption, but hey!
Anyway, For some reason - the computer always selects rock no matter what the previous move is. I don't understand why that is!

Here's the relevant code

Interface:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

enum move{rock,paper,scissor};

class RocksPapersScissors
{
	public:
		RocksPapersScissors();//Possibly problematic
		move getMove();//Fine
		move counterAttack();//Possibly Problematic
		void decideWinner();//Fine
		void printOutcome();//Fine
	private:
		void previousify();//Checked..Fine
		bool ComputerWonPrevious;
		move Random();//For now, just returns rock
		move PreviousComputerMove;
		move PreviousHumanMove;
		move CurrentHumanMove;
		move CurrentComputerMove;
		string WinStatus;
};


Implementation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

RocksPapersScissors::RocksPapersScissors()
{
	ComputerWonPrevious=false;
	PreviousHumanMove=Random();
	PreviousComputerMove=Random();
	WinStatus="No Value";
}

move RocksPapersScissors::counterAttack()
{
	if(ComputerWonPrevious)
	{
		switch(PreviousComputerMove)
		{
			case rock:{CurrentComputerMove=scissor;}
			case paper:{CurrentComputerMove=rock;}
			case scissor:{CurrentComputerMove=paper;}
			default: {CurrentComputerMove=Random();}
		}
	}
	
	else 
	{
		switch(PreviousHumanMove)
		{
			case rock:{CurrentComputerMove=paper;}
			case paper:{CurrentComputerMove=scissor;}
			case scissor:{CurrentComputerMove=rock;}
			default: {CurrentComputerMove=Random();}
		}	
	}		
}


void RocksPapersScissors::printOutcome()
{ previousify(); /*the rest...*/ }
}

void RocksPapersScissors::previousify()
{
	PreviousComputerMove = CurrentComputerMove;
	PreviousHumanMove = CurrentHumanMove;
}

move RocksPapersScissors::Random()
{	return rock; }


Main
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
	RocksPapersScissors player;
	while(1)
	{
		player.getMove();
		player.counterAttack();
		player.decideWinner();
		player.printOutcome();
	}
	return 0;
}


BTW: Are long function names acceptable? I use em cuz they're kinda more readable.
Last edited on
http://www.cplusplus.com/doc/tutorial/control/
break;

Good old rock, nothing beats it
Last edited on
Can't believe I missed that, Thanks!!
:D
Topic archived. No new replies allowed.