联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> Python程序Python程序

日期:2020-10-22 08:35

3. Notakto
Weight: 25%
In this question, you are going to implement a human vs. human version of Notakto.
Notakto is a tic-tac-toe variant. It is played across three 3 x 3 boards: Board A, board B and board C. When you start the game you should output the boards as follows.
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1:
There are two players: Player 1 and player 2. Player 1 always starts. Both players play the same piece: X. E.g., let player 1 choose location 6 on board A, i.e., the user will enter A6. The output of the program should be as follows (bold font represents user input).
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: A6
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X 7 8 6 7 8 6 7 8
Player 2:
Each player takes turn placing an X on the board in a vacant space (a space not already occupied by an X).
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: A6
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X 7 8 6 7 8 6 7 8
Player 2: A7
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X X 8 6 7 8 6 7 8
Player 1:
If a board has three X in a row, column, or diagonal, the board is dead and it cannot be played anymore. It should not be displayed anymore. E.g., in the following, board A becomes dead and is not displayed anymore.
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: A6
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X 7 8 6 7 8 6 7 8
Player 2: A7
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X X 8 6 7 8 6 7 8
Player 1: A8
B C
0 1 2 0 1 2
3 4 5 3 4 5
6 7 8 6 7 8
Player 2:
The game ends when all the boards contain three X in a row, column, or diagonal, at which point the player to have made the last move loses the game. Unlike tic-tac-toe, there will always be a player who wins any game of Notakto.
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: A6
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X 7 8 6 7 8 6 7 8
Player 2: A7
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
X X 8 6 7 8 6 7 8
Player 1: A8
B C
0 1 2 0 1 2
3 4 5 3 4 5
6 7 8 6 7 8
Player 2: B0
B C
X 1 2 0 1 2
3 4 5 3 4 5
6 7 8 6 7 8
Player 1: B4
B C
X 1 2 0 1 2
3 X 5 3 4 5
6 7 8 6 7 8
Player 2: C0
B C
X 1 2 X 1 2
3 X 5 3 4 5
6 7 8 6 7 8
Player 1: C4
B C
X 1 2 X 1 2
3 X 5 3 X 5
6 7 8 6 7 8
Player 2: C8
B
X 1 2
3 X 5
6 7 8
Player 1: B8
Player 2 wins game
Note that you should check for legal moves. If the users enters something illegal you should prompt them again. Let's play a new game to illustrate this.
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: C0
A B C
0 1 2 0 1 2 X 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 2: B9
Invalid move, please input again
Player 2: fds
Invalid move, please input again
Player 2: C0
Invalid move, please input again
Player 2: C6
A B C
0 1 2 0 1 2 X 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 X 7 8
Player 1: C6
Invalid move, please input again
Player 1: C3
A B
0 1 2 0 1 2
3 4 5 3 4 5
6 7 8 6 7 8
Player 2: C2
Invalid move, please input again
Player 2:
Implement the game and try to pass all test cases. The list of test cases is not complete. We may add more test cases when marking after the deadline.
You may use any functions/operators for this question.
4. Notakto - AI
Weight: 25%
In this question, you are going to implement an artificial intelligence (AI) vs. human version of Notakto. The AI will be the Player 1, i.e., the AI will always start. Here the AI means that the move of player 1 is determined by your program automatically. You should finish the previous question first before working on this one. All output / input requirements are identical to the previous question. The only difference is that you replace Player 1 with an AI, i.e., don't wait for user input and let your program decide the valid move.
In Notakto, Player 1 can force a win. It doesn't matter how Player 2 plays. If Player 1 plays optimally there should be a win for Player 1. In this task your AI must always win. Here is an example run (bold font represents user input).
A B C
0 1 2 0 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: B0
A B C
0 1 2 X 1 2 0 1 2
3 4 5 3 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 2: B3
A B C
0 1 2 X 1 2 0 1 2
3 4 5 X 4 5 3 4 5
6 7 8 6 7 8 6 7 8
Player 1: B6
A C
0 1 2 0 1 2
3 4 5 3 4 5
6 7 8 6 7 8
Player 2: C0
A C
0 1 2 X 1 2
3 4 5 3 4 5
6 7 8 6 7 8
Player 1: C3
A C
0 1 2 X 1 2
3 4 5 X 4 5
6 7 8 6 7 8
Player 2: C6
A
0 1 2
3 4 5
6 7 8
Player 1: A0
A
X 1 2
3 4 5
6 7 8
Player 2: A4
A
X 1 2
3 X 5
6 7 8
Player 1: A7
A
X 1 2
3 X 5
6 X 8
Player 2: A8
Player 1 wins game
There will be no student site automatic marking for this question. Please perform your own testing and ensure that you never win against your AI. We suggest that you finish the previous question first and then copy over your code from there and only change the part where player 1 (your AI implementation) is moving.
We will mark your code by playing a number of games against an optimal AI. Your AI must win all games to get full marks for this question.
Important: Implementing an optimal AI that is able to always win does not require complex computation. Your AI must be very fast. We will use a time threshold of 1 second per move. You are allowed to discuss solution strategies for this question. But don't share any code.
You may use any functions/operators for this question.

版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。