Esempio n. 1
0
 def get_winner(self, last_move, current_player, row_size=4):
   assert self.grid.at(last_move) is not DiscState.empty
   if grid_utils.is_in_row_run(self.grid, last_move, row_size) or \
       grid_utils.is_in_col_run(self.grid, last_move, row_size) or \
       grid_utils.is_in_diag_down_run(self.grid, last_move, row_size) or \
       grid_utils.is_in_diag_up_run(self.grid, last_move, row_size):
       return current_player
   return None
Esempio n. 2
0
 def get_winner(self, last_move, current_player, row_size=4):
     assert self.grid.at(last_move) is not DiscState.empty
     if grid_utils.is_in_row_run(self.grid, last_move, row_size) or \
         grid_utils.is_in_col_run(self.grid, last_move, row_size) or \
         grid_utils.is_in_diag_down_run(self.grid, last_move, row_size) or \
         grid_utils.is_in_diag_up_run(self.grid, last_move, row_size):
         return current_player
     return None
def get_winning_move(grid, current_player):
  for col_index in range(grid.width):
    row_index = grid_utils.get_row_of_first(grid, col_index, DiscState.empty)
    current_point = Point(row_index, col_index)
    if not grid.is_inside(current_point):
      continue

    if grid_utils.is_in_row_run(grid, current_point, 4, current_player):
      return col_index
    if grid_utils.is_in_col_run(grid, current_point, 4, current_player):
      return col_index
    if grid_utils.is_in_diag_down_run(grid, current_point, 4, current_player):
      return col_index
    if grid_utils.is_in_diag_up_run(grid, current_point, 4, current_player):
      return col_index

  else:
    return None
Esempio n. 4
0
def get_winning_move(grid, current_player):
    for col_index in range(grid.width):
        row_index = grid_utils.get_row_of_first(grid, col_index,
                                                DiscState.empty)
        current_point = Point(row_index, col_index)
        if not grid.is_inside(current_point):
            continue

        if grid_utils.is_in_row_run(grid, current_point, 4, current_player):
            return col_index
        if grid_utils.is_in_col_run(grid, current_point, 4, current_player):
            return col_index
        if grid_utils.is_in_diag_down_run(grid, current_point, 4,
                                          current_player):
            return col_index
        if grid_utils.is_in_diag_up_run(grid, current_point, 4,
                                        current_player):
            return col_index

    else:
        return None