Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem I see is that your self.get_position does not do what you want it to do. </p> <pre><code>def get_position(self, row, column): assert row &gt;= 0 and row &lt; 6 and column &gt;= 0 and column &lt; 7 if self.get_position == 1: # the type of self.get_position is a function, and it will never be equal to 1, or 2, so it always goes to None return 1 elif self.get_position == 2: return 2 else: return None </code></pre> <p>Another problem is that you never used board, and you never store your data at any place.<br> If I were you, I would first consider how I would store the data.<br> An obvious option is a two-dimension array.</p> <pre><code>self.board = [[0 for i in range(6)] for j in range(7)] </code></pre> <p>When you call play_turn, try to update the column, eg you already have [0,0,0,0,2,1] on column 3, you would try to get the index of the first element that is not 0. Then put the new player index on the element before it, so it goes to [0,0,0,1,2,1] (if the piece belongs to player 1).</p> <p>Then, actually with a column number and a row number, you want to check what is on the board. Whether it is 0 or 1 or 2.<br> you'd better call it get_player_num or something like that. You do not get position but the player number of the piece at that position.</p> <p>An example. If I have a 2 * 2 array in a class:</p> <pre><code>class CF(object): def __init__(self): board = [[0, 0], [0, 0]] </code></pre> <p>This represents a 2 * 2 field, now they are all empty.<br> 0 0<br> 0 0</p> <p>I could design an update method:</p> <pre><code>def update(self, col, row, newVal): self.board[col - 1][row - 1] = newVal </code></pre> <p>If a do:</p> <pre><code>game = CF() game.update(1, 2, 1) </code></pre> <p>Then the board becomes<br> 0 0<br> 1 0</p> <p>While reading the board, I know at column 1, row 2 is a piece of player 1.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload