[Tutor] help with tic-tac-toe program
joel.goldstick at gmail.com
Sun Nov 16 20:35:00 CET 2014
On Sun, Nov 16, 2014 at 1:52 PM, Andrew McReynolds
<amcreynolds3 at yahoo.com.dmarc.invalid> wrote:
> The section of the assignment that I'm working on states:
> 2) Write a function called loadGameBoard (player_marks) where player_marks
> is a dictionary that
> contains the players’ marks. This function creates a 3x3 array with the
> players’ marks populated in
> the correct row/column indices using the formula 3*row+column. This function
> returns the 3x3
> array. You must use a loop at least once.
> 3) Write a function called printGameBoard (gameBoard) where gameBoard is a
> 3x3 array that
> contains the players’ marks. This function draws the game board and returns
> None. You must
> use a loop at least once in this function or in a function that this
> function calls.
> An example is if gameBoardArray has ‘X’ and gameBoardArray has
> ‘O’, this function should
> draw the game board like:
> | | X | |
> | | O | |
> | | | |
A few style points:
1.Normally people use all lower case for function names with
underscore to separate words.
2. Use plain text to write your question. It makes it easier to understand
3. What is player_marks? Can you show what the data looks like in player_parks?
4. You might want to rename null to empty. For me that would make it
easier to understand.
> What I have so far is:
> def loadGameBoard (player_marks):
> null= " "
> board= [[null,null,null],[null,null,null],[null,null,null]]
> for row in range(3):
> for column in range (3):
> position = 3*row+column
> if position in player_marks["X"]:
> if position in player_marks["O"]:
> return (board)
> def printGameBoard(gameBoard):
> board=(("-"*8,("| ")*4))*3
> #for line in board:
> return ()
> Any advice for continuing?
What happens when you run your code?
> Thanks in advance for assistance,
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor