Exemple #1
0
 def initialize_players(self,
                        start_row,
                        start_index,
                        num_of_pawns,
                        p1=True):
     rows, cols = self.board.shape
     num_rows_to_fill = math.ceil(num_of_pawns / (cols / 2))
     pawn_id = 1
     for row in range(start_row, start_row + num_rows_to_fill):
         for col in range(start_index, cols, 2):
             if pawn_id > num_of_pawns:
                 break
             if (p1):
                 self.board[row, col] = pawn_id
                 self.p1_pawns[pawn_id] = pawn.Pawn(pawn_id, row, col,
                                                    start_row)
                 pawn_id += 1
             else:
                 self.board[row, col] = -pawn_id
                 self.p2_pawns[-pawn_id] = pawn.Pawn(
                     -pawn_id, row, col, start_row)
                 pawn_id += 1
         if start_index == 0:
             start_index = 1
         else:
             start_index = 0
    def __init__(self):

        self.pieces = [
            pawn.Pawn("Black"),
            rook.Rook("Black"),
            knight.Knight("Black"),
            bishop.Bishop("Black"),
            queen.Queen("Black"),
            king.King("Black"),
            pawn.Pawn("White"),
            rook.Rook("White"),
            knight.Knight("White"),
            bishop.Bishop("White"),
            queen.Queen("White"),
            king.King("White")
        ]

        self.starting_board = [
            self.__build_rank_with_king(0, 4),
            self.__build_rank_without_king(0, 4),
            ["-", "-", "-", "-", "-", "-", "-", "-"],
            ["-", "-", "-", "-", "-", "-", "-", "-"],
            ["-", "-", "-", "-", "-", "-", "-", "-"],
            ["-", "-", "-", "-", "-", "-", "-", "-"],
            self.__build_rank_without_king(6, 10),
            self.__build_rank_with_king(6, 10)
        ]
Exemple #3
0
def init_pawns(pawns):
    for row in range(8):
        for col in range(8):
            # two top rows
            if (row == 0 and col % 2 != 0) or (row == 1 and col % 2 == 0) or \
                (row == 2 and col % 2 != 0):
                pawns.append(pawn.Pawn(row, col, 0))
                # two bottom rows
            elif (row == 5 and col % 2 == 0) or (row == 6 and col % 2 != 0) or \
                (row == 7 and col % 2 == 0):
                pawns.append(pawn.Pawn(row, col, 1))
    # returning initialized pawns
    return pawns
Exemple #4
0
    def set_pawns(self):
        id_numb = 0
        for x, y in self._chessboard:
            id_numb += 1

            if (x + y) % 2 == 0:
                if y < self.size_y / 2:
                    self._chessboard[x, y] = pawn.Pawn(color='w',
                                                       id_number=id_numb)
                    self.numb_of_w_pawns += 1
                if y > self.size_y / 2 + 1:
                    self._chessboard[x, y] = pawn.Pawn(color='b',
                                                       id_number=id_numb)
                    self.numb_of_b_pawns += 1
Exemple #5
0
 def __init__(self):
     self.playBoard = dict()
     self.rows = 7
     self.columns = 8
     for i in range(
             97, 98 + self.rows
     ):  # letters for columns, with 'a' at the top and 'i' at the bottom
         if (i == 97 or i == 98):
             colour = 'B'
         elif (i == 96 + self.rows or i == 97 + self.rows):
             colour = 'W'
         for j in range(
                 1, self.columns + 1
         ):  # numbers for rows, with 1 at the left and 8 at the right
             index = str(chr(i)) + str(j)
             if (i == 97 or i
                     == 97 + self.rows):  # essentially a factory method
                 if (j == 1 or j == 8):
                     self.playBoard[index] = rook.Rook(0, True, colour, j)
                 elif (j == 2 or j == 7):
                     self.playBoard[index] = knight.Knight(
                         0, True, colour, j)
                 elif (j == 3 or j == 6):
                     self.playBoard[index] = bishop.Bishop(
                         0, True, colour, j)
                 elif (j == 4):
                     self.playBoard[index] = queen.Queen(0, True, colour, j)
                 else:
                     self.playBoard[index] = king.King(0, True, colour, j)
             elif (i == 98 or i == 96 + self.rows):
                 self.playBoard[index] = pawn.Pawn(0, True, colour, j)
             else:
                 self.playBoard[index] = '0'
Exemple #6
0
def get_piece(symbol, rank, file, has_moved=False):
    import pawn, knight, bishop, rook, queen, king

    if symbol == ' ':
        return None
    elif symbol > '♙':
        colour = -1
        symbol = chr(ord(symbol) - ord('♚') + ord('♔'))
    else:
        colour = 1

    if symbol == '♔':
        return king.King(colour, rank, file, has_moved)
    elif symbol == '♕':
        return queen.Queen(colour, rank, file)
    elif symbol == '♖':
        return rook.Rook(colour, rank, file, has_moved)
    elif symbol == '♗':
        return bishop.Bishop(colour, rank, file)
    elif symbol == '♘':
        return knight.Knight(colour, rank, file)
    elif symbol == '♙':
        return pawn.Pawn(colour, rank, file)
    else:
        return None
Exemple #7
0
def create_pawns_on_chessboard(chessTilesSprintTable: pygame.sprite.Group):
    pawnsSprintTable = pygame.sprite.Group()

    for index, tile in enumerate(chessTilesSprintTable):
        tileSize = tile.image.get_width()
        if index <= 15:
            pawn_var = pawn.Pawn('black')
            pawnsSprintTable.add(pawn_var)
            pawn_var.set_pawn_position(tile.rect.x + (tileSize - pawn_var.image.get_width()) / 2,
                                 tile.rect.y + (tileSize - pawn_var.image.get_width()) / 2)
        elif index >= 48:
            pawn_var = pawn.Pawn('white')
            pawnsSprintTable.add(pawn_var)
            pawn_var.set_pawn_position(tile.rect.x + (tileSize - pawn_var.image.get_width()) / 2,
                                 tile.rect.y + (tileSize - pawn_var.image.get_width()) / 2)

    return pawnsSprintTable
 def assign(self, plist, aturn):
     if aturn:
         for j in range(self.n):
             c = plist[j]
             p = re.compile('P[0-9]')
             if p.match(c):
                 self.board[4][j] = pawn.Pawn('A', c[1])
             elif c == 'H1':
                 self.board[4][j] = hero1.Hero1('A')
             elif c == 'H2':
                 self.board[4][j] = hero2.Hero2('A')
     else:
         for j in range(self.n):
             c = plist[j]
             p = re.compile('P[0-9]')
             if p.match(c):
                 self.board[0][4 - j] = pawn.Pawn('B', c[1])
             elif c == 'H1':
                 self.board[0][4 - j] = hero1.Hero1('B')
             elif c == 'H2':
                 self.board[0][4 - j] = hero2.Hero2('B')
Exemple #9
0
    def set_standard_board(self):
        """
        Sets the Board with the standard Chess Opening
        """
        white = 'white'
        black = 'black'

        # Pawn
        for i in range(8):
            self.set_piece(PAWN.Pawn(white), self.alphabet[i], 2)
        for i in range(8):
            self.set_piece(PAWN.Pawn(black), self.alphabet[i], 7)

        # Rooks
        self.set_piece(ROOK.Rook(white), 'A', 1)
        self.set_piece(ROOK.Rook(white), 'H', 1)
        self.set_piece(ROOK.Rook(black), 'A', 8)
        self.set_piece(ROOK.Rook(black), 'H', 8)

        # Knights
        self.set_piece(KNIGHT.Knight(white), 'B', 1)
        self.set_piece(KNIGHT.Knight(white), 'G', 1)
        self.set_piece(KNIGHT.Knight(black), 'B', 8)
        self.set_piece(KNIGHT.Knight(black), 'G', 8)

        # Bishops
        self.set_piece(BISHOP.Bishop(white), 'C', 1)
        self.set_piece(BISHOP.Bishop(white), 'F', 1)
        self.set_piece(BISHOP.Bishop(black), 'C', 8)
        self.set_piece(BISHOP.Bishop(black), 'F', 8)

        # Queens
        self.set_piece(QUEEN.Queen(white), 'D', 1)
        self.set_piece(QUEEN.Queen(black), 'D', 8)

        # Kings
        self.set_piece(KING.King(white), 'E', 1)
        self.set_piece(KING.King(black), 'E', 8)
Exemple #10
0
    def __init__(self, name, player_direction, logger=None):
        self.logger = logger or logging.getLogger(__name__)
        self.logger.info("player created with name: {}".format(name))
        self.name = name

        # create walls
        self.walls = [
            wall.Wall(wall.TYPE_PLAYER, i) for i in range(NUMBER_OF_WALLS)
        ]

        # create pawn
        self.pawn = pawn.Pawn(board.PAWN_INIT_POS[player_direction])
        self.board = None
        self.player_direction = player_direction

        # at_move
        self._active = False
import pytest
import pawn
from piece import Piece
import game
from standard_rules import StandardRules

test_pawn_b = pawn.Pawn("Black")
test_pawn_w = pawn.Pawn("White")

@pytest.fixture(autouse=True)
def run_before_tests():
        test_game = game.Game('p1', 'p2', ruleset = StandardRules())
        return test_game

class TestpawnProperties:

    def test_pawn_name(self):
      assert test_pawn_b.name == "Pawn"
      assert test_pawn_w.name == "Pawn"
      
    def test_pawn_symbol(self):
      assert test_pawn_b.symbol == '♟'
      assert test_pawn_w.symbol == "♙"

class TestIllegalMoves:

    def test_pawn_cannot_move_backwards(self):
      assert test_pawn_b.invalid_move_types(1, 0, 0, 0) == True
      assert test_pawn_w.invalid_move_types(6, 2, 7, 2) == True

    def test_pawn_cannot_move_laterally(self):
import pytest
import pawn
import player

test_pawn = pawn.Pawn("Black")


class TestPlayerProperties:
    def test_player_name(self):
        test_player_1 = player.Player("test_name_1", "White")
        assert test_player_1.name == "test_name_1"

    def test_player_colour(self):
        test_player_1 = player.Player("test_name_1", "White")
        assert test_player_1.colour == "White"

    def test_player_captured_pieces_storage(self):
        test_player_1 = player.Player("test_name_1", "White")
        assert test_player_1.taken_pieces == []

    def test_player_current_score(self):
        test_player_1 = player.Player("test_name_1", "White")
        assert test_player_1.current_score == 0


class TestPlayerActions:
    def test_player_captured_pieces(self):
        test_player_1 = player.Player("test_name_1", "White")
        test_player_1.store_piece(test_pawn)
        assert test_player_1.taken_pieces == [test_pawn]
Exemple #13
0
            print('Cannot move to that position!' + ' (' + str(x) + ', ' +
                  str(y) + ')')

    # is the given position checked by given color
    def isChecckedBy(self, x, y, color):
        result = False
        if (color != 'B' and color != 'W' and color != 'N'):
            print('Wrong color!')
        else:
            for r in self.actualBoard:
                for piece in r:
                    if (piece != None):
                        if (piece.color == color):
                            for move in piece.availableMoves(self):
                                if ((x, y) == move):
                                    result = True
        return result


# do testów
test = ChessBoard()
pawn = pawn.Pawn(2, 2, 'B')
knight = knight.Knight(3, 1, 'W')
test.addPiece(pawn)
test.addPiece(knight)

test.showBoard()

moves = pawn.availableMoves(test)
print(moves)
Exemple #14
0
         ("King",450,750),
         ("Queen",350,750),
         ("Rook",50,750),
         ("Rook",750,750),
         ]

WHITE2 = []
BLACK2 = []

# How I append horse3 to a list is something we don't want to do. Just immediately append them to the list.
# Look into cases which should be used here and see if it is less code and/or more effective.
# Make a function Init pieces.
# This could be done wayyyyyyyyyyyyy nicer
for i in WHITE:
    if i[0] == "Pawn":
        WHITE2.append(pawn.Pawn(i[1],i[2], "WHITE"))
    elif i[0] == "Knight":
        WHITE2.append(knight.Knight(i[1],i[2], "WHITE"))
    elif i[0] == "Bishop":
        WHITE2.append(bishop.Bishop(i[1],i[2], "WHITE"))
    elif i[0] == "King":
        WHITE2.append(king.King(i[1],i[2], "WHITE"))
    elif i[0] == "Queen":
        WHITE2.append(queen.Queen(i[1],i[2], "WHITE"))
    elif i[0] == "Rook":
        WHITE2.append(rook.Rook(i[1],i[2], "WHITE"))

for i in BLACK:
    if i[0] == "Pawn":
        BLACK2.append(pawn.Pawn(i[1],i[2], "BLACK"))
    elif i[0] == "Knight":
Exemple #15
0
    def setupBoard(self, board):
        white_king = None
        black_king = None

        # Get all squares of interest
        eligible_squares = [
            square for square in self.squares if square.rank == 1
            or square.rank == 2 or square.rank == 7 or square.rank == 8
        ]

        for square in eligible_squares:

            # Set the colour
            if square.rank == 1 or square.rank == 2:
                colour = 'white'
            else:
                colour = 'black'

            # Determine which piece to be created based on rank and column
            if square.rank == 2 or square.rank == 7:
                piece = pawn.Pawn(square, colour)

            else:
                if square.file == 'A' or square.file == 'H':
                    piece = rook.Rook(square, colour)

                elif square.file == 'B' or square.file == 'G':
                    piece = knight.Knight(square, colour)

                elif square.file == 'C' or square.file == 'F':
                    piece = bishop.Bishop(square, colour)

                elif square.file == 'D':
                    piece = queen.Queen(square, colour)

                else:
                    piece = king.King(square, colour)
                    if square.id == 'E1':
                        white_king = piece
                    else:
                        black_king = piece

            self.pieces.add(piece)

            # While we are here, set square.isOccupied to be True, since when square objects are created, these are set to be False.
            square.isOccupied = True
            square.occupied_colour = colour

            self.screen.blit(piece.image, piece.rect)
            pg.display.update()

        # Add pieces to appropriate groups
        for piece in self.pieces:
            if piece.colour == 'white':
                self.white_pieces.add(piece)
            else:
                self.black_pieces.add(piece)

        # We need to get the legal moves for each piece on startup, since if a king is selected to move
        # we need to check that no opponent's piece is controlling a given surrounding square of that king.
        # But since knights can move before every other piece has been moved, we account for that by getting every piece's available moves right away.
        for piece in self.pieces:

            # Get the legal moves for the current piece.
            if piece.name == 'King':
                piece.get_legal_moves(self.squares, self.pieces, None, None)
                if piece.colour == 'white':
                    white_king = piece
                else:
                    black_king = piece
            else:
                piece.get_legal_moves(self.squares, self.pieces, None, None)

            # Update pawn attribute.
            if piece.name == 'Pawn':
                piece.first_move = True

            # Now get each piece's king and its opponent's king.
            for k in [piece for piece in self.pieces if piece.name == 'King']:
                if piece.colour == k.colour:
                    piece.our_king = k
                else:
                    piece.opponents_king = k

        return white_king, black_king
Exemple #16
0
import sys
sys.path.append('../Pieces')
import pawn as PAWN
import queen as QUEEN
sys.path.append('../BoardStuff')
import board as BOARD

# Variables
white = 'white'
black = 'black'
b_true = BOARD.Board()
b_test = BOARD.Board()

# Set Boards
#   True Board
b_true.set_piece(PAWN.Pawn(black), 'C', 7)
b_true.set_piece(PAWN.Pawn(black), 'F', 7)
b_true.set_piece(PAWN.Pawn(black), 'H', 7)
b_true.set_piece(PAWN.Pawn(white), 'D', 6)
b_true.set_piece(PAWN.Pawn(white), 'G', 6)
b_true.set_piece(PAWN.Pawn(black), 'A', 5)
b_true.set_piece(PAWN.Pawn(white), 'H', 4)
b_true.set_piece(PAWN.Pawn(black), 'A', 3)
b_true.set_piece(PAWN.Pawn(white), 'F', 3)
b_true.set_piece(QUEEN.Queen(black), 'B', 1)

#   Test Board
b_test.has_king = False
b_test.set_piece(PAWN.Pawn(white), 'A', 2)
b_test.set_piece(PAWN.Pawn(white), 'B', 2)
b_test.set_piece(PAWN.Pawn(white), 'C', 2)
Exemple #17
0
def main():
    #Initialize Everything
    sound_controler = Sound()

    db = database.Database('localhost', 27017)

    pygame.init()
    if sys.version_info[0] < 3:
        pygame.display.set_caption((u'武将大乱斗').encode('utf-8'))
    else:
        pygame.display.set_caption(u'武将大乱斗')

    hero.initiate_hero_pool(db)

    current_map = Map(name='map-1',team_count=3)
    sprite.Sprite.current_map = current_map
    screen = pygame.display.set_mode((current_map.map_width + 256, current_map.map_height))
    current_map.init_terrain_mask()
    skill.load_skill_images()

    gui_controller = gui.Gui(current_map, screen)

    current_mission = mission.test_mission

    #yun = pawn.Pawn((9,6) ,pawn.DIRECTION_RIGHT , pawn.ARM_MELEE , pawn.MOBILE_MOUNT, hero.hero_pool[0] , 0 , True , False)
    #lvbu = pawn.Pawn((6,5) , pawn.DIRECTION_LEFT ,  pawn.ARM_MELEE , pawn.MOBILE_MOUNT, hero.hero_pool[1] , 1 , False , True)
    #zhouyu = pawn.Pawn((6,6) , pawn.DIRECTION_LEFT ,  pawn.ARM_MELEE , pawn.MOBILE_WALK, hero.hero_pool[2] , 1 , False , True)
    #guanyu = pawn.Pawn((8,9) , pawn.DIRECTION_LEFT ,  pawn.ARM_MELEE , pawn.MOBILE_MOUNT, hero.hero_pool[3] , 0 , True , False)
    #weiwen = pawn.Pawn((10,9) , pawn.DIRECTION_LEFT ,  pawn.ARM_MELEE , pawn.MOBILE_WALK, hero.hero_pool[4] , 0 , True , False)

    #yun.action_turn = 0
    #lvbu.action_turn = 1
    #zhouyu.action_turn = 1
    #guanyu.action_turn = 0
    #
    #pawn_list = [yun , lvbu , zhouyu  , guanyu , weiwen]
    pawn_list = []
    for roster in current_mission.player_roster:
        p = pawn.Pawn(roster[1], roster[2], roster[3], roster[4], hero.hero_pool[roster[0]], roster[5], 0, roster[6],
                      roster[7])
        pawn_list.append(p)
    for roster in current_mission.friend_roster:
        h = copy.copy(hero.hero_pool[roster[0]])
        p = pawn.Pawn(roster[1], roster[2], roster[3], roster[4], h, roster[5], 1, roster[6], roster[7])
        p.ai_group = roster[9][0]
        p.is_leader = roster[9][1]
        p.ai_strategy = roster[10]
        pawn_list.append(p)
    for roster in current_mission.enemy_roster:
        h = copy.copy(hero.hero_pool[roster[0]])
        p = pawn.Pawn(roster[1], roster[2], roster[3], roster[4], h, roster[5], 2, roster[6], roster[7])
        p.persuade = roster[8]
        p.ai_group = roster[9][0]
        p.is_leader = roster[9][1]
        p.ai_strategy = roster[10]
        pawn_list.append(p)

    selected_pawn = None
    control = Control(current_map)
    gui_controller.side_menu(selected_pawn)
    logic_controller = logic.Logic(current_map, pawn_list)
    fight_logic_controller = fight_logic.FightLogic(current_map, pawn_list)
    skill.fight_logic_controller = fight_logic_controller

    logic_controller.process_action_queue()
    logic_controller.turn_team = 0
    logic.control = control
    logic.fight_logic_controller = fight_logic_controller

    ai.logic_controller = logic_controller
    gui.logic_controller = logic_controller
    info_before_move = (None, None, None)

    ai_controller = ai.AI(pawn_list)

    logic_controller.new_turn()

    current_round = 1
    last_turn_team = 0

    while True:

        config.clock = pygame.time.Clock().tick(config.FPS)

        current_map.render()

        logic_controller.update_terrain_mask()
        skill.fight_logic_controller.trigger_passive_skills_realtime()
        logic_controller.update_pawn_status()

        for p in logic_controller.pawn_list:
            if p.hero.alive:
                p.render()
            else:
                pawn_list.remove(p)


        #FOR ENEMY AI
        if logic_controller.turn_team != 0:
            for event in pygame.event.get():
                if event.type == QUIT:
                    return

            flag = False
            for p in ai_controller.pawn_list:
                if p.turn_team != logic_controller.turn_team:
                    continue
                if not p.turn_finished and p.has_ai:
                    if control.status == control.CONTROL_STATUS_IDlE:
                        ai_controller.take_action(p)
                        if p and p.next_move:
                            top = p.next_move[0]
                            action_type = top[0]
                            action_target = top[1]
                            if action_type == ai.AI_ACTION_MOVE:
                                logic_controller.process_player_action(p, action_target)
                                control.status = control.CONTROL_STATUS_PROCESSING_PLAYER_ACTION
                            elif action_type == ai.AI_ACTION_ATTACK:
                                logic_controller.process_player_action(p, action_target , MENU_ORDER_ATTACK)
                                control.status = control.CONTROL_STATUS_PROCESSING_PLAYER_ACTION
                            #print p.hero.name.encode('utf-8'), ' not finished', p.next_move, 'control status: ', control.status , logic_controller.turn_team , p.turn_team
                        flag = True
                        break
                    elif control.status == control.CONTROL_STATUS_PAWN_MOVED:
                        control.status = control.CONTROL_STATUS_PROCESSING_PLAYER_ACTION
                    flag = True
            if not flag:
                control.status = control.CONTROL_STATUS_TURN_FINISHING

            if control.status == control.CONTROL_STATUS_PROCESSING_PLAYER_ACTION:
                if not logic_controller.process_action_queue():
                    control.status = control.CONTROL_STATUS_IDlE
        else:
            for event in pygame.event.get():
                if event.type == QUIT:
                    return
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_p:
                        if debug and selected_pawn:
                            logger(  selected_pawn.status_info() )

                if control.status == control.CONTROL_STATUS_MENU_ATTACK_CHOOSE:
                    target = gui_controller.get_grid_on_mouse()
                    target_type = logic_controller.is_valid_target(selected_pawn, target, pawn.ACTION_ATTACK, )
                elif control.status == control.CONTROL_STATUS_MENU_OPENED:
                    target_type = gui_controller.is_mouse_on_menu()
                else:
                    target = gui_controller.get_grid_on_mouse()
                    target_type = logic_controller.get_target_type(0, target)
                if event.type == KEYDOWN or event.type == MOUSEBUTTONDOWN or event.type == MOUSEBUTTONUP:
                    control.event_queue.append((event, target_type))

            if control.status == control.CONTROL_STATUS_MENU_OPENED:

                #当鼠标在地图上右键, 打开菜单

                if gui_controller.menu is None:
                    gui_controller.build_menu(None)
                gui_controller.menu.display()
            elif control.status == control.CONTROL_STATUS_MENU_ITEM_SELECTING:
                gui_controller.menu.display(1)

            elif control.status == control.CONTROL_STATUS_PAWN_MOVED or control.status == control.CONTROL_STATUS_MENU_ATTACK_CHOOSE_CANCELED:
                gui_controller.build_menu(selected_pawn)
                control.status = control.CONTROL_STATUS_MENU_OPENED

            elif control.status == control.CONTROL_STATUS_MENU_CANCEL:

                #战斗菜单被取消后, 单位回到操作前的状态(包括位置,方向)

                gui_controller.menu = None
                if selected_pawn:
                    logic_controller.current_map.map_collision_info[selected_pawn.position[0]][
                        selected_pawn.position[1]] = battle_map.COLLISION_INFO_EMPTY

                    selected_pawn.position = info_before_move[0]
                    selected_pawn.direction = info_before_move[1]
                    selected_pawn.move_count = info_before_move[2]
                    selected_pawn.render_position = selected_pawn.get_render_position(selected_pawn.position)
                    logic_controller.current_map.map_collision_info[selected_pawn.position[0]][
                        selected_pawn.position[1]] = battle_map.COLLISION_INFO_OCCUPIED

                control.status = control.CONTROL_STATUS_IDlE


            elif control.status == control.CONTROL_STATUS_MENU_ITEM_SELECTED:
                control.status = control.get_control_status_by_menu_order(gui_controller.selected_menu_item)
                logic_controller.process_menu_order(selected_pawn, gui_controller.selected_menu_item)

            elif control.status == Control.CONTROL_STATUS_PROCESS_PLAYER_ACTION:

                if target and selected_pawn:
                    order = None
                    if gui_controller.selected_menu_item:
                        order = gui_controller.selected_menu_item.order
                    logic_controller.process_player_action(selected_pawn, target , order)
                    control.status = Control.CONTROL_STATUS_PROCESSING_PLAYER_ACTION

            elif control.status == control.CONTROL_STATUS_PAWN_SELECTED:

                if selected_pawn:
                    info_before_move = (selected_pawn.position, selected_pawn.direction , selected_pawn.move_count)
                    valid_move = logic_controller.get_valid_move(selected_pawn)

                    gui_controller.highlight_valid_move(valid_move, selected_pawn.controllable)
                    attack_range = logic_controller.get_attack_range_grids(selected_pawn)
                    gui_controller.draw_attack_frame_on_target(attack_range)


            elif control.status == control.CONTROL_STATUS_PROCESSING_PLAYER_ACTION:
                if not logic_controller.process_action_queue():
                    control.status = control.CONTROL_STATUS_IDlE
            elif control.status == control.CONTROL_STATUS_MENU_ATTACK_CHOOSE:
                valid_target = logic_controller.get_valid_target(selected_pawn)
                gui_controller.highlight_valid_target(valid_target)

                attack_range = logic_controller.get_attack_range_grids(selected_pawn)
                gui_controller.draw_attack_frame_on_target(attack_range)
                if selected_pawn.taunted_to:
                    gui_controller.highlight_taunting_target(valid_target)
            elif control.status == control.CONTROL_STATUS_MENU_PERSUADE_CHOOSE:
                valid_target = logic_controller.get_persuade_target(selected_pawn)
                gui_controller.highlight_valid_target(valid_target)
            else:
                selected_pawn = gui_controller.get_selected_pawn(pawn_list)

        if control.status == control.CONTROL_STATUS_TURN_FINISHING:
            if (gui_controller.switch_turn(logic_controller.turn_team)):
                logic_controller.end_turn()
                control.status = control.CONTROL_STATUS_IDlE
        else:
            control.process_event()

        if control.status not in (
            control.CONTROL_STATUS_MENU_OPENED,
            control.CONTROL_STATUS_MENU_BUILD,
            control.CONTROL_STATUS_MENU_ITEM_SELECTING
        ):
            gui_controller.menu = None
            gui_controller.draw_selection_frame()
            gui_controller.side_menu(selected_pawn)

        render_queue.sort(key=lambda surface:surface[0])

        while render_queue:
            top = render_queue.pop()
            if top[1] and top[2]:
                screen.blit(top[1], top[2])

        gui_controller.draw_border()

        pygame.display.update()
 def __init__(self):
     self.starting_board = [[
         rook.Rook("Black"),
         knight.Knight("Black"),
         bishop.Bishop("Black"),
         queen.Queen("Black"),
         king.King("Black"),
         bishop.Bishop("Black"),
         knight.Knight("Black"),
         rook.Rook("Black")
     ],
                            [
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black"),
                                pawn.Pawn("Black")
                            ], ["-", "-", "-", "-", "-", "-", "-", "-"],
                            ["-", "-", "-", "-", "-", "-", "-", "-"],
                            ["-", "-", "-", "-", "-", "-", "-", "-"],
                            ["-", "-", "-", "-", "-", "-", "-", "-"],
                            [
                                pawn.Pawn("White"),
                                pawn.Pawn("White"),
                                pawn.Pawn("White"),
                                pawn.Pawn("White"),
                                pawn.Pawn("White"),
                                pawn.Pawn("White"),
                                pawn.Pawn("White"),
                                pawn.Pawn("White")
                            ],
                            [
                                rook.Rook("White"),
                                knight.Knight("White"),
                                bishop.Bishop("White"),
                                queen.Queen("White"),
                                king.King("White"),
                                bishop.Bishop("White"),
                                knight.Knight("White"),
                                rook.Rook("White")
                            ]]
Exemple #19
0
import game
import pawn
import bishop
import knight
import queen
import rook
import king
import gui
from tkinter import NW

alpha = ['H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', 'X']
alpha2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
game = game.Game()

#team white
Wpawn1 = pawn.Pawn('H2', 'white', game)
Wpawn2 = pawn.Pawn('G2', 'white', game)
Wpawn3 = pawn.Pawn('F2', 'white', game)
Wpawn4 = pawn.Pawn('E2', 'white', game)
Wpawn5 = pawn.Pawn('D2', 'white', game)
Wpawn6 = pawn.Pawn('C2', 'white', game)
Wpawn7 = pawn.Pawn('B2', 'white', game)
Wpawn8 = pawn.Pawn('A2', 'white', game)

Wknight1 = knight.Knight("B1", "white", game)
Wknight2 = knight.Knight("G1", "white", game)

Wbishop1 = bishop.Bishop("F1", "white", game)
Wbishop2 = bishop.Bishop("C1", "white", game)

Wrook1 = rook.Rook("H1", "white", game)
# Variables
white = 'white'
black = 'black'
b_true = BOARD.Board()
b_test = BOARD.Board()

# Set Boards
#   True Board
b_true.set_piece(KING.King(white), 'G', 1)
b_true.set_piece(KING.King(black), 'E', 8)
b_true.set_piece(ROOK.Rook(black), 'H', 8)
b_true.set_piece(ROOK.Rook(black), 'A', 8)
b_true.set_piece(ROOK.Rook(white), 'F', 1)
b_true.set_piece(ROOK.Rook(white), 'A', 1)
b_true.set_piece(PAWN.Pawn(white), 'G', 7)
b_true.set_piece(PAWN.Pawn(black), 'B', 2)
b_true.set_piece(ROOK.Rook(black), 'E', 7)
b_true.set_piece(ROOK.Rook(white), 'E', 2)

#   Test Board
b_test.set_piece(KING.King(white), 'E', 1)
b_test.set_piece(KING.King(black), 'E', 8)
b_test.set_piece(ROOK.Rook(black), 'H', 8)
b_test.set_piece(ROOK.Rook(black), 'A', 8)
b_test.set_piece(ROOK.Rook(white), 'H', 1)
b_test.set_piece(ROOK.Rook(white), 'A', 1)
b_test.set_piece(PAWN.Pawn(white), 'G', 7)
b_test.set_piece(PAWN.Pawn(black), 'B', 2)
b_test.set_piece(ROOK.Rook(black), 'E', 7)
b_test.set_piece(ROOK.Rook(white), 'D', 2)
    def makeChessboard(self):
        # # Make Square Objects
        # # column
        # current_num = 1
        # for y in range(1, 9):
        #     # row
        #     for x in range(1, 9):
        #         if current_num % 2 == 0:
        #             color = "WHITE"
        #         else:
        #             color = "BLACK"
        #         SSquare = [x, y, color]
        #         self.squares.append(SSquare)
        #         current_num += 1
        # for i in range(len(self.squares)):
        #     temp_square = Square.Square(self.squares[i][0], self.squares[i][1], self.squares[i][2])  # make a square object
        #     self.squareObjs.append(temp_square)

        y = 1  # row
        x = 1  # column
        number = 1
        count = "Piece" + str(number)
        # WHITE PIECES
        for i in range(17):
            team = "WHITE"
            if x > 8:
                x = 1
                y += 1
            if y == 2:
                piece = pawn.Pawn(x, y, team, count)
                self.list_of_pieces.append(piece)
                self.dict_of_pieces[count] = piece
                number += 1
                x += 1
                continue
            elif x == 1 or x == 8:
                piece = rook.Rook(x, y, team, count)
            elif x == 2 or x == 7:
                piece = knight.Knight(x, y, team, count)
            elif x == 3 or x == 6:
                piece = bishopBase.Bishop(x, y, team, count)
            elif x == 4:
                piece = queen.Queen(x, y, team, count)
            elif x == 5:
                piece = king.King(x, y, team, count)
            self.list_of_pieces.append(piece)
            self.dict_of_pieces[count] = piece
            x += 1
            number += 1
        r = 7
        c = 1
        # BLACK PIECES
        number = 17
        count = "Piece" + str(number)
        for i in range(33):
            team = "BLACK"
            if c > 8:
                c = 1
                r += 1
            if r == 7:
                piece = pawn.Pawn(c, r, team, count)
                self.list_of_pieces.append(piece)
                self.dict_of_pieces[count] = piece
                number += 1
                c += 1
                continue
            elif c == 1 or c == 8:
                piece = rook.Rook(c, r, team, count)
            elif c == 2 or c == 7:
                piece = knight.Knight(c, r, team, count)
            elif c == 3 or c == 6:
                piece = bishopBase.Bishop(c, r, team, count)
            elif c == 4:
                piece = queen.Queen(c, r, team, count)
            elif c == 5:
                piece = king.King(c, r, team, count)
            self.list_of_pieces.append(piece)
            self.dict_of_pieces[count] = piece
            number += 1
            c += 1