Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #James Nguyen
  2.  
  3. DIRECTIONS = [[0,-1],[-1,1],[1,-2],[0,1],[-1,1],[1,1],[-1,0],[1,0]]
  4. class Game_state:
  5.  
  6. def __init__(self,row_col,player):
  7.  
  8. self.first_player = player
  9. self.second_player = self.switch_player(player)
  10.  
  11. self.row = row_col[1]
  12. self.col = row_col[0]
  13. self.board = self.create_board(player)
  14.  
  15.  
  16. def create_board(self,startingplayer):
  17.  
  18. board_list = []
  19. for row in range(self.col):
  20. list_items = []
  21. for col in range(self.row):
  22. list_items.append(' ')
  23. board_list.append(list_items)
  24.  
  25. #print(board_list[0] == # of columns
  26.  
  27.  
  28. #rowcol[1] = COLUMN
  29. #rowcol[0] == row
  30. opposite_player = self.switch_player(startingplayer)
  31. pos1 = int(self.col/2)
  32. pos2 = int(self.row/2)
  33.  
  34. board_list[pos1][pos2-1] = startingplayer
  35. board_list[pos1][pos2] = opposite_player
  36. board_list[pos1-1][pos2]= startingplayer
  37. board_list[pos1-1][pos2-1]= opposite_player
  38.  
  39. return board_list
  40.  
  41.  
  42. def make_move(self,player):
  43. cur_player = player
  44. print('It\'s ' + str(player)+ 's turn')
  45.  
  46. print('Select row and column to make move')
  47. row = int(input('Row: '))
  48. col = int(input('Col: '))
  49.  
  50. # self.isValid(row,col)
  51. #self.validmoves(cur_player)
  52. self.valid_moves(cur_player)
  53.  
  54. def switch_player(self,player):
  55.  
  56. if player == 'W':
  57. return 'B'
  58. else:
  59. return 'W'
  60.  
  61. ## def _checkDisc(self,row,col):
  62. ## '''Checks if there is an empty cell'''
  63. ##
  64. ## if self.board[row][col] == ' ':
  65. ## return True
  66. ## else:
  67. ## return False
  68. ##
  69. def valid_moves(self,player):
  70.  
  71. for row in range(len(self.board)):
  72.  
  73. for col in range(self.col):
  74. if self.board[col][row] == player: # returns the position of a player
  75.  
  76. for direction in DIRECTIONS: # goes through all possible directions
  77.  
  78. self.search_directions(direction,col,row,player)
  79.  
  80.  
  81. def search_directions(self,direction,row,col,player):
  82.  
  83. #while True:
  84. col_move = col #+ #direction[0]
  85. row_move = row #+ direction[1]
  86. cur_list = []
  87.  
  88. if not self._is_in_board(row_move,col_move):
  89. return False
  90. print('it works1')
  91.  
  92. while True:
  93.  
  94. col_move+=direction[0]
  95. row_move+=direction[1]
  96. print('it works asdfadf')
  97.  
  98. if self._is_in_board(row_move,col_move):
  99.  
  100. if self.board[col_move][row_move] == self.switch_player(player):
  101. print('it works2')
  102. self.continue_direction(col_move,row_move,direction)
  103.  
  104. else:
  105. return True
  106. #elif not self._is_in_board(row_move,col_move) or self.board[col_move][row_move] == player:
  107. # return False
  108.  
  109. else:
  110. print(col_move,row_move)
  111. for i in self.board:
  112. print(i)
  113. break
  114.  
  115. print(cur_list)
  116. def continue_direction(self,col,row,direction):
  117. while True:
  118. col+=direction[0]
  119. row+=direction[1]
  120. list1 = []
  121. if self.board[col][row] == ' ':
  122. list1.append([col,row])
  123. print(list1)
  124.  
  125. for i in self.board:
  126. print(i)
  127. return False
  128. else:
  129. return True
  130.  
  131.  
  132.  
  133.  
  134. def _is_in_board(self,row,col)->bool:
  135. return col >=0 and col<= self.col -1 and row >= 0 and row<= self.row-1
  136.  
  137. def _isEmpty(self):
  138. pass
  139. def _isColor(self,row,col,player):
  140.  
  141. return self.board[col][row] == player
  142.  
  143.  
  144.  
  145.  
  146.  
  147. def check_winner(self):
  148. pass
  149. def _tilesflip(self):
  150. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement