Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You can find a copy of java implementation of the minimax version of the tic-tic

ID: 669256 • Letter: Y

Question

You can find a copy of java implementation of the minimax version of the tic-tic-toe
zipped with this document.
The objective of this assignment is for you to identify a scoring technique that is better
than the one presented in class and implemented by the attached code.   You will then
have to modify my code to include your scoring technique. Please note that you may not
alter the mini-max algorithm, just the scoring of the leaf node.
Please provide me a typed description of your solution and an explanation of why you
think your scoring technique is better than the one presented in class. hand me a hard copy of your code with
your modifications highlighted on the hard copy.

Package tic-tac-toe;

public class TicTacToeMain {

public TicTacToeMain() {

}

public static void main(String[] args) throws Exception{

    TicTacToeMain ticTacToeMain1 = new TicTacToeMain();

    ticTacToeMain1.userInstruct();

    TicTacToe tictactoe;

    do{

      tictactoe = new TicTacToe();

      while (!(tictactoe.checkForWin() || tictactoe.getTurn() == 10)){

        if((tictactoe.getComputerPlaysOddTurns() && tictactoe.getTurn()%2 == 1) || //computer plays odd turns and this is an odd turn

          (!tictactoe.getComputerPlaysOddTurns() && tictactoe.getTurn()%2 == 0)) //computer plays even turns and this is an even turn

          tictactoe.playAHandForComputer();

        else

          tictactoe.playAHandForUser();

          tictactoe.display();

      }

      tictactoe.display();

      if(tictactoe.getTurn() == 10)

        System.out.println("Tie Game!");

      else{

        if((tictactoe.getComputerPlaysOddTurns() && (tictactoe.getTurn()-1)%2 == 1) || //computer plays odd turns and this is an odd turn

             (!tictactoe.getComputerPlaysOddTurns() && (tictactoe.getTurn()-1)%2 == 0)) //computer plays even turns and this is an even turn

            System.out.println("I WIN! Best luck next time.");

        else

            System.out.println("YOU WIN :-(");

      }

    }while (tictactoe.userWantsToPlayAnotherGame());

  return;

}

void userInstruct(){

          System.out.println("Welcome to the game of tic-tac-toe");

          System.out.println("PLEASE NOTE that X will always play first.");

          System.out.println("GOOD LUCK!");

          return;

}

}

Explanation / Answer

Hi,

I think you can modify the scoring system as below:

Simple enough, return +10 if the current player wins the game, -10 if the other player wins and 0 for a draw.

Your program doesn't check for rows,columns and diagonals for win and hence is not a good way of choosing a winner.

Implementation of scoring function:

/ Returns true if there is a win, false otherwise.
// This calls our other win check functions to check the entire board.
public boolean checkForWin() {
return (checkRowsForWin() || checkColumnsForWin() || checkDiagonalsForWin());
}
// Loop through rows and see if any are winners.
private boolean checkRowsForWin() {
for (int i = 0; i < 3; i++) {
if (checkRowCol(board[i][0], board[i][1], board[i][2]) == true) {
return true;
}
}
return false;
}
// Loop through columns and see if any are winners.
private boolean checkColumnsForWin() {
for (int i = 0; i < 3; i++) {
if (checkRowCol(board[0][i], board[1][i], board[2][i]) == true) {
return true;
}
}
return false;
}
// Check the two diagonals to see if either is a win. Return true if either wins.
private boolean checkDiagonalsForWin() {
return ((checkRowCol(board[0][0], board[1][1], board[2][2]) == true) || (checkRowCol(board[0][2], board[1][1], board[2][0]) == true));
}

Hope that helps...HAPPY ANSWERING!!!!!!!!!!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote