关于人脸识别:Python代码编写CSC108H-TicTacToe

3次阅读

共计 1339 个字符,预计需要花费 4 分钟才能阅读完成。

全文链接:http://tecdat.cn/?p=29592Requ… 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!AnalysisTic-tac-toe 又称井字棋,通常是在 3 ×3 的棋盘上,单方轮流落子,先将 3 枚棋子连成一线的一方获胜。本题将游戏进行了拓展,变为 NxN 的棋盘,加大了难度。咱们须要依据提供的框架实现游戏的逻辑局部,尤其是 AI 局部。解题的要害须要了解游戏的规定,读懂整个框架,找到切入点,依据给定的测试集一直调试即可。Tips 从测试集动手 >>> game_won(‘XXX-O-O–‘, ‘X’)True>>> game_won(‘XOXOXOOXO’, ‘X’)False 从__main__开始一路调试,到 def play_tictatoe(): … hava_a_winner = game_won(game_board, player_symbol) 进入函数后,减少解决逻辑,外围代码如下 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

正文完
 0