sos game

Status
Not open for further replies.

daleachacon

Beta member
Messages
1
guys can you help me about my homework... we are asssigned to create a one player game of "mini SoS" here's the specification:

Create a one player game of “Mini SOS”.

The game of “Mini SOS” is played on a 3 by 3 game board.

There are 2 players in the game – the user vs. the computer. The user is given the option if he/she would like to go first. The 2 players alternate turn. During a player’s turn, he/she can choose an empty square from the table and write an ‘S’ or an ‘O’.

HereÂ’s how the computer decides its next move.
If it can win the game with its current move, it will take the win.
Otherwise, it will randomly take any open square and randomly write an ‘S’ or an ‘O’.

The first player to form the word SOS on 3 squares of any row, column or main diagonal of the board game wins the game. If all squares were filled up without any player winning, the result of the game is considered a tie/draw. Upon a win or a draw, the game ends. At the end of the game, the computer shall declare who won the game. Afterwards, the computer will ask if the player wants to play again.

Possible Additional Specifications

1.Different levels of difficulty (easy, hard, difficult)
The given algorithm on how the computer decides is not very smart. If you want to implement your own algorithm, do so but still implement what is included in the specification.
2.Use of arrays and subprograms to improve the readability and to shorten the length of your code.
3.Graphics
4.Scoring System
5.Others
 

Iron_Cross

Daemon Poster
Messages
549
Location
Bamberg, Germany
What language are you writting it in, C, C++, or C#? It'd be pretty easy to implement as a GUI Program in C#. And farily easy to implement as a Command Line Program in C or C++ (C# too, but might as well do GUI if it's in C# :p ).

But either way, use a 2 dimensional array to represent the game board in memory. i.e.

Code:
char[] brd = new char[3][3];

The board would be set up like this:
--------------------
| 0,0 | 0,1 | 0,2 |
--------------------
| 1,0 | 1,1 | 1,2 |
--------------------
| 2,0 | 2,1 | 2,2 |
--------------------

So to access 1,0 you'd do it like:
brd[1][0] = 's';
Or to access 2,2 you'd do it like:
brd[2][2] = 'o';
Etc.

If you want, you could use another array to keep track of which sqares are open, i.e.:
Code:
string[] opnSqrs = new string[12];
opnSqrs[0] = "0,0";
opnSqrs[1] = "0,1";
opnSqrs[2] = "0,2";
opnSqrs[3] = "1,0";
Then to find out if the squre is still free, use
Code:
Random rand = new Random();
int chkSqr;
bool rep = true;
while(rep){
chkSqr = rand.Next(3);
if(opnSqrs[chkSqr] != "")
    rep = false;
}
char mv;
int iMv = rand.Next(2);
switch(iMv){
    case 0:
          mv = 'o';
          break;
    case 1:
          mv = 's';
          break;
    default:
          mv = 's';
          break;
}
brd[Convert.ToInt32(opnSqrs[chkSqr].Chars[0])][Convert.ToInt32(opnSqrs[chkSqr].Chars[1])] = mv;
opnSqrs[chkSqr] = "";

Hope this helps you some ;)
Oh, and this is all in C#, so if you're not using C# you'll have to port it over to your language...
 

jo_er86

Beta member
Messages
2
code....

can i have the source code for the SOS game... I also have the same homework but it has to be a 10X10 board. THnx :)
 
Status
Not open for further replies.
Top