Requirement

留学生作业代写,网课代修-英国、澳大利亚、北美代写等 is a two-player game that children often play to pass the time. The game is usually played using a 3-by-3 game board. Each player chooses a symbol to play with (usually an X or an O) and the goal is to be the first player to place 3 of their symbols in a straight line on the game board (either across a row on the board, down a column or along one of the two main diagonals).

In this Assignment, you are to complete some functions that make up part of a larger program for playing tic-tac-toe. In the program, game boards are not restricted to being 3-by-3, but are instead N-by-N, where N is one of the integers from 1 through 9, inclusive. Our game boards will always be square. When you have completed your functions for this Assignment, you will be able to play games of tic-tac-toe on your computer!

Analysis

Tic-tac-toe又稱,通常是在3x3的棋盤上,雙方輪流落子,先將3枚棋子連成一線的一方獲勝。本題將游戲進行了拓展,變為NxN的棋盤,加大了難度。我們需要根據提供的框架實現游戲的邏輯部分,尤其是AI部分。
解題的關鍵需要理解游戲的規則,讀懂整個框架,找到切入點,根據給定的測試集不斷調試即可。

Tips

從測試集入手

1
2
3
4
>>> game_won('XXX-O-O--', 'X')
True
>>> game_won('XOXOXOOXO', 'X')
False

從__main__開始一路調試,到

1
2
3
def play_tictatoe():
...
hava_a_winner = game_won(game_board, player_symbol)

進入函數后,增加處理邏輯,核心代碼如下

1
2
3
4
5
6
7
8
9
10
11
12
def game_won(game_board, symbol):
...
for col in range(1, board_size + 1):
extract = tictactoe_functions.extract_line(game_board, 'dowm', col)
if extract == winning_string:
return True
for row in range(1, board_size + 1):
extract = tictactoe_functions.extract_line(game_board, 'across', row)
if extract == winning_string:
return True
...
return False

19 分類
51 標簽
微信
Essay_Cheery
郵箱
[email protected]

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信