[SOLVED] 代写 C game AI 1. Notakto Human vs. Human

30 $

File Name: 代写_C_game_AI_1._Notakto__Human_vs._Human.zip
File Size: 414.48 KB

SKU: 9529701454 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


1. NotaktoHuman vs. Human
In this question, you are going to implement a human vs. human version of Notakto.
Notakto is a tictactoe 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.
ABC
012 012 012
345 345 345
678 678 678
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.
ABC
012 012 012
345 345 345
678 678 678
Player 1: A6
ABC
012 012 012
345 345 345
X78 678 678
Player 2:
Each player takes turn placing an X on the board in a vacant space a space not already occupied by an X.
ABC
012 012 012
345 345 345
678 678 678
Player 1: A6
ABC
012 012 012
345 345 345
X78 678 678
Player 2: A7
ABC
012 012 012
345 345 345
XX8 678 678
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 example, board A becomes dead and is not displayed anymore.
ABC 012 012 012 345 345 345 678 678 678 Player 1: A6 ABC 012 012 012 345 345 345

X78 678 678 Player 2: A7 ABC
012 012 012 345 345 345 XX8 678 678 Player 1: A8 BC
012 012
345 345
678 678
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 tictactoe, there will always be a player who wins any game of Notakto.
ABC
012 012 012 345 345 345 678 678 678 Player 1: A6 ABC
012 012 012 345 345 345 X78 678 678 Player 2: A7 ABC
012 012 012 345 345 345 XX8 678 678 Player 1: A8 BC
012 012
345 345
678 678 Player 2: B0 BC
X12 012
345 345
678 678 Player 1: B4 BC
X12 012
3X5 345
678 678 Player 2: C0 BC
X12 X12
3X5 345
678 678 Player 1: C4 BC
X12 X12
3X5 3X5
678 678

Player 2: C8 B
X12
3X5
678
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. Lets play a new game to illustrate this.
ABC
012 012 012
345 345 345
678 678 678
Player 1: C0
ABC
012 012 X12
345 345 345
678 678 678
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
ABC
012 012 X12
345 345 345
678 678 X78
Player 1: C6
Invalid move, please input again
Player 1: C3
AB
012 012
345 345
678 678
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.
My Answer:
table0 for a in range3 for b in range3 for c in range3 p1
aliveA, B, C
def assignvalue:
for a in range3: for b in range3:
for c in range3: tableabc3bc
def letternumberletter:

if letterA: return 0
if letterB: return 1
if letterC: return 2
def showtable: for i in alive:
if alivelenalive1i: printi, endn
else:
printi, end
for b in range3: for a in alive:
for c in range3:
if alivelenalive1a and c2:
endn elif c2:
endelse:
end
printtableletternumberabc, endend
def tictactoea,b,c: if bc2:
for i in range3:
if tableai2iX:
if i2: return True
else: break
for i in range3:
if tableaicX:
if i2: return True
else: break
if bc:
for i in range3:
if tableaiiX: if i2:
return True else:
break for i in range3:
if tableabiX: if i2:
return True else:
break return False
def checkpossibleornots: if lens2:
if s0 in alive: try:
if ints10 and ints18:

if tableletternumbers0intints13ints13 ! X: return True
else:
return False
else:
return False
except ValueError: return False
else:
return False
else:
return False
assignvalue
forin iterint, 1:
showtable
forin iterint, 1:
stinputPlayer s: p if checkpossibleornotst:
tableletternumberst0intintst13intst13X
if tictactoeletternumberst0, intintst13, intst13 ! False:
alive.removest0 break
else:
printInvalid move, please input again
pp1 pp2 if p0:
p2
if lenalive0:
p2
if lenalive0:
printPlayer strp wins game break
2. NotaktoAI vs. Human
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 outputinput requirements are identical to the previous question. The only difference is that you replace Player 1 with an AI, i.e., dont wait for user input and let your program decide the valid move.
In Notakto, Player 1 can force a win. It doesnt 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.
ABC 012 012 012 345 345 345 678 678 678 Player 1: B0 ABC 012 X12 012 345 345 345

678 678 678 Player 2: B3 ABC 012 X12 012 345 X45 345 678 678 678 Player 1: B6 AC
012 012 345 345 678 678 Player 2: C0 AC 012 X12 345 345 678 678 Player 1: C3 AC 012 X12 345 X45 678 678 Player 2: C6 A
012
345
678
Player 1: A0 A
X12
345
678
Player 2: A4 A
X12
3X5
678
Player 1: A7 A
X12
3X5
6X8
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 dont share any code.

3. Safety map
Two maps are shown below.
The one on the left gives the dangerous chemical map. The one on the right shows the safety map.
In the dangerous chemical map, a cell value is:
1denote the existence of a dangerous chemical.
0no dangerous chemical in that location.
In the safety map, a location is considered to be
Safe safety1 if there is no chemical around its 3×3 neighbourhood, and
Super safe safety2 if there is no chemical around its 5×5 neighbourhood, and Dangerous chemical safety if there exists a dangerous chemical in that location

safety0 Otherwise
Write a program that reads in the map on left, and output the map on right.
You can assume that both the maps square have the same number of rows and columns Sample test cases The bolded text are user input
101000000
001010110
010000001
000000010
010000000
000000010
100000000
001011000
000110000
0000000
00000
0000000
00011100
00121000
00011100
00000000
000011
1000012

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 C game AI 1. Notakto Human vs. Human
30 $