Changeset 336

Show
Ignore:
Timestamp:
11/12/11 19:54:07 (6 months ago)
Author:
sud2
Message:

Some very small updates to the GameBoard class.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Checkers/src/GameBoard.py

    r334 r336  
    1414    ABS_BOTTOM_RIGHT = 7 
    1515    NOCAP_DRAW_TURNS = 40 
     16     
     17    DIRECTIONS = [FORWARD_LEFT, FORWARD_RIGHT, BACKWARD_LEFT, BACKWARD_RIGHT] 
    1618 
    1719    def __init__( self ): 
     
    9294            # indicate player one victory 
    9395            # and quit 
    94             print "Player 1 WON!" 
     96            print("Player 1 WON!") 
    9597            self.resign() 
    9698        elif victor == GameBoard.PLAYER_TWO: 
    9799            # indicate player two victory 
    98100            # and quit 
    99             print "Player 2 WON!" 
     101            print ("Player 2 WON!") 
    100102            self.resign() 
    101103        elif victor == -1: 
    102104            # Indicate draw and quit. 
    103             print "Game is a draw!" 
     105            print ("Game is a draw!") 
    104106            self.resign() 
    105107        else: 
     
    327329    def get_pieces( self ): 
    328330        ''' 
    329         Gets a 2D list of all the pieces on the gameboard 
    330         Unclear for now 
    331         @return list - a 2D list of all the pieces on the gameboard 
     331        Gets a 1D list of all the pieces on the gameboard 
     332        @return list - a 1D list of all the pieces on the gameboard 
    332333        ''' 
    333334        pieces = [] 
     
    336337                if self.board[x][y] != None: 
    337338                    pieces.append(self.board[x][y]) 
     339        return pieces 
     340 
     341 
     342    def get_pieces_for_player(self, player): 
     343        ''' 
     344        Gets a 1D list of all the pieces for the given player 
     345        @return list - a 1D list of all the pieces on the gameboard for the given player 
     346        ''' 
     347        pieces = [] 
     348        for row in range(len(self.board)): 
     349                for col in range(len(self.board[row])): 
     350                    if self.board[row][col] != None and (self.board[row][col]).player == player: 
     351                        pieces.append(self.board[row][col]) 
    338352        return pieces 
    339353 
     
    599613                if print_rows%2 == 0: 
    600614                    if print_columns%2 == 0: 
    601                         print ' +'
     615                        print (' +')
    602616                    else: 
    603                         print ' -'
     617                        print (' -')
    604618                else: 
    605619                    if print_columns%2 == 0: 
    606620                        if print_columns == 0: 
    607                             print ''
    608                         print '|'
     621                            print ('')
     622                        print ('|')
    609623                    else: 
    610624                        y = (print_rows-1)/2 
     
    612626                        piece = self.board[x][y] 
    613627                        if piece == None: 
    614                             print '   '
     628                            print ('   ')
    615629                            continue 
    616                         if piece.player == GameBoard.PLAYER_ONE: 
    617                             print GREEN, 
     630                        print (''), 
     631                        if piece.is_king: 
     632                            print ('K'), 
    618633                        else: 
    619                             print BLUE, 
    620                         if piece.is_king: 
    621                             print 'K', 
    622                         else: 
    623                             print 'O'
    624                         print ENDC
    625             print ' ' # new line 
     634                            if piece.player == GameBoard.PLAYER_ONE: 
     635                                print ('G'), 
     636                            else: 
     637                                print ('B'), 
     638#                            print ('O')
     639                        print (ENDC)
     640            print (' ') # new line 
    626641        # end print_board