国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

Python代碼編寫:CSC108H Tic-Tac-Toe

2022-10-25 15:18 作者:拓端tecdat  | 我要投稿

全文鏈接:tecdat.cn/?p=29592

Requirement

Tic-tac-toe?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枚棋子連成一線的一方獲勝。本題將游戲進(jìn)行了拓展,變?yōu)镹xN的棋盤,加大了難度。我們需要根據(jù)提供的框架實(shí)現(xiàn)游戲的邏輯部分,尤其是AI部分。
解題的關(guān)鍵需要理解游戲的規(guī)則,讀懂整個(gè)框架,找到切入點(diǎn),根據(jù)給定的測試集不斷調(diào)試即可。

Tips

從測試集入手

>>> game_won('XXX-O-O--', 'X')True>>> game_won('XOXOXOOXO', 'X')False 復(fù)制代碼

從__main__開始一路調(diào)試,到

def play_tictatoe(): ?... ?hava_a_winner = game_won(game_board, player_symbol) 復(fù)制代碼

進(jìn)入函數(shù)后,增加處理邏輯,核心代碼如下

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 復(fù)制代碼


Python代碼編寫:CSC108H Tic-Tac-Toe的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
寿阳县| 于田县| 潍坊市| 耿马| 探索| 曲周县| 依安县| 北碚区| 乌鲁木齐县| 武汉市| 柳江县| 梁平县| 郁南县| 华池县| 宜君县| 拉孜县| 天全县| 灌阳县| 平邑县| 宁安市| 顺义区| 峨边| 呈贡县| 东方市| 安阳县| 安庆市| 大城县| 恭城| 合川市| 胶州市| 辽中县| 岐山县| 金乡县| 阳泉市| 汉中市| 新余市| 正宁县| 马山县| 萍乡市| 扎囊县| 衡阳市|