Starting from:

$25

CS160- Assignment 10 Solved

Problem Analysis:

The users inputs will be the number of players playing, 1 or 2. Then we’ll ask what character player 1 wants to be and player2 will get the leftover character. Another major input is the coordinates for which the player wants to put their character. We’ll have to check that it’s in the range of the board and that no character is already there. They’ll be a lot of function calls for not only checking if the game is won, by either getting three in a row, diagonal right, diagonal left, and in one column.

 

 

Problem Design:

First thing I need to do is ask how many players are playing, I’ll do this inside main. Next after checking the input to be valid I will set the other players character as the one not chosen. I’ll do this at the start for player2 and for the A.I. Next if there’s only one player I’ll have a while loop that’ll continue if all the check_to_win functions are false. These are the diagonal left, diagonal right programs I discussed earlier. If those are false then in the while loop I’ll ask the player for the row they want to put their character then the column they want to put the character. After checking that it’s a valid input I’ll edit the board and input their character at the inputted coordinates. Next I’ll have a function that randomizes the row and column of the A.I. and checks to make sure no character is already there if so it’ll input the coordinates to the board and set that location to the A.I. character. Once the game is won, depending on who won I’ll have a print statement saying who won and congrats.

If there’s two players I’ll be the same set up as player1 but instead of the A.I. I’ll just have a set up like player1 but for player2. I’ll be printing the pretty board at the start of every while loop.

 

·    Test Cases

·      Input
Expected
Actual meet expectation
Enter 1 for number of players
Continue program as only one player
Yes
Enter 2 for number of players
Continue program as only two players
Yes
Enters any other number
Will say I entered an incorrect number of players
Yes

 
Enter a x for the character
Will use x as player1’s character
Yes
Enter a y for the character
Will use y as player1’s character
Yes
Enters any other character
Will say wrong input
Yes
 

More products