s40923224 cp2020

  • Home
    • Site Map
    • reveal
    • blog
  • 首頁
  • HW1
    • IPv4 與 IPv6 地址
      • Overview 總覽-1
      • TCP and IP TCP與IP
      • IPv4 and IPv6 Addresses IPv4 與 IPv6 位址
      • IPv4 Addressing IPv4 位址
      • Addressing Notation 尋址符號
      • Network and Host Addresses 網絡和主機地址
      • IPv4 Address Classes IPv4地址類別
      • IPv4 Data Flows IPv4數據流
      • Assigning an IP Address 分配IP地址
      • Benefits of IPv6 IPv6的好處
      • IPv6 Address Structure IPv6地址結構
      • IPv6 Data Flows IPv6數據流
    • TCP 與 UDP 協議
      • Overview 總覽-2
      • TCP and UDP TCP與UDP
      • TCP Vs. UDP
      • TCP Windowing TCP窗口
      • Networking Transfer Protocols 網絡傳輸協議
  • HW2
  • HW3
    • Concepts 概念
    • MAX OF THREE 最多三人
    • Tic Tac Toe Game 井字遊戲
  • 心得
  • 自評分數60
HW2 << Previous Next >> Concepts 概念

HW3


Exercise 27 (and Solution)

In a previous exercise we explored the idea of using a list of lists as a “data structure” to store information about a tic tac toe game. In a tic tac toe game, the “game server” needs to know where the Xs and Os are in the board, to know whether player 1 or player 2 (or whoever is X and O won).

There has also been an exercise about drawing the actual tic tac toe gameboard using text characters.

The next logical step is to deal with handling user input. When a player (say player 1, who is X) wants to place an X on the screen, they can’t just click on a terminal. So we are going to approximate this clicking simply by asking the user for a coordinate of where they want to place their piece.

As a reminder, our tic tac toe game is really a list of lists. The game starts out with an empty game board like this:

game = [[0, 0, 0],
	[0, 0, 0],
	[0, 0, 0]]

The computer asks Player 1 (X) what their move is (in the format row,col), and say they type 1,3. Then the game would print out

game = [[0, 0, X],
	[0, 0, 0],
	[0, 0, 0]]

And ask Player 2 for their move, printing an O in that place.

Things to note:

  • For this exercise, assume that player 1 (the first player to move) will always be X and player 2 (the second player) will always be O.
  • Notice how in the example I gave coordinates for where I want to move starting from (1, 1) instead of (0, 0). To people who don’t program, starting to count at 0 is a strange concept, so it is better for the user experience if the row counts and column counts start at 1. This is not required, but whichever way you choose to implement this, it should be explained to the player.
  • Ask the user to enter coordinates in the form “row,col” - a number, then a comma, then a number. Then you can use your Python skills to figure out which row and column they want their piece to be in.
  • Don’t worry about checking whether someone won the game, but if a player tries to put a piece in a game position where there already is another piece, do not allow the piece to go there.

Bonus:

  • For the “standard” exercise, don’t worry about “ending” the game - no need to keep track of how many squares are full. In a bonus version, keep track of how many squares are full and automatically stop asking for moves when there are no more valid moves.

HW2 << Previous Next >> Concepts 概念

Copyright © All rights reserved | This template is made with by Colorlib