Tic Tac Toe Game pseudocode
Alright, so basically I am to create a tic tac toe game in pseudocode. Which sucks because I can't see output. Anyways,
/*
*Program by: Cory
*Program: Tic Tac Toe game
*
*/
Module Main()
Boolean player = true
Constant Integer ROWS = 3, COLS = 3
Declare String values[ROWS][COLS] = "*", "*", "*",
"*", "*", "*",
"*", "*", "*"
Call Module getIntro()
Call Module showBoard(values[][], ROWS, COLS)
Call Module playGame(values[][], COLS, ROWS, player)
End Module
Module getIntro()
Display "Hello, this is a simple tic tac toe game."
Display "It will rotate turns between players one and two,"
Display "While 3,3 would be the bottom right."
Display "Player 1 is X and player 2 is O"
End Module
Module showBoard(String values[][], Integer rows, Integer cols)
Declare Integer row, col
For row = 0 to rows - 1
For col = 0 to cols - 1
Display values[rows][cols]
End For
End For
End Module
Module playGame(String values[][], Integer cols, Integer rows, Boolean player) //places moves, checks for already placed moves
Declare Integer row, col
player = true
For row = 0 to rows - 1
For col = 0 to cols -1
If (player == true)
Display "First player's turn, please input your move"
Input values[row][col]
if (checkMove(values[][], rows, cols) == false)
Display "Invalid move, please try again"
Display "First player's turn again, please input your move"
Input values[row][col]
End If
values[row][col] = "X"
showBoard(values[row][col], rows, cols)
checkWin()
player = false
Else If (player == false)
Display "Second player's turn, please input your move"
Input values[row][col]
if (checkMove(values[][], rows, cols) == false)
Display "Invalid move, please try again"
Display "Second player's turn again, please input your move"
Input values[row][col]
End If
values[row][col] = "O"
showBoard(values[row][col], rows, cols)
checkWin()
player = true
End For
End For
End Module
Function Boolean checkMove(String values[][], Integer cols, Integer rows)
Declare Integer row, col
For row = 0 to rows - 1
For col = 0 to cols - 1
if (values[row][col] != "*")
Display "Player has already placed a move there"
End If
End For
End For
return false
End Function
Module checkWin()
checkRow(values[][], 3)
checkCol(values[][], 3)
checkDiagonal(values[][], 3, 3)
End Module
Module checkRow(String values[][], Integer rows) //checks horizontal win
Declare Integer row, col
For row = 0 to rows - 1
if (values[row][0] == "X")
Display "Player one has won!"
//player1Win = true
Else if (values[row][0] == "O")
Display "Player two has won!"
//player1Win = false
End If
End For
End Module
Module checkCol(String values[][], Integer cols) //checks vertical win
Declare Integer row, col
For col = 0 to cols -1
if (values[0][col] == "X")
Display "Player one has won!"
//player1Win = true
Else if (values[0][col] == "O")
Display "Player two has won!"
//player1Win = false
End If
End For
End Module
Module checkDiagonal(String values[][], Integer cols, Integer rows, Boolean player1Win) //checks Diagonal win
So 1) please look over my code and tell me if I'm doing something wrong or if there's a way I can make it look better 2) I need help checking for diagonal wins. 3) checking for ties