示例#1
0
    def possible_playing_positions(game_state: CarcassonneGameState,
                                   tile_to_play: Tile) -> [PlayingPosition]:
        if game_state.empty_board():
            return [
                PlayingPosition(coordinate=game_state.starting_position,
                                turns=0)
            ]

        playing_positions = []

        for row_index, board_row in enumerate(game_state.board):
            for column_index, column_tile in enumerate(board_row):
                if column_tile is not None:
                    continue

                for tile_turns in range(0, 4):
                    top = game_state.get_tile(row_index - 1, column_index)
                    bottom = game_state.get_tile(row_index + 1, column_index)
                    left = game_state.get_tile(row_index, column_index - 1)
                    right = game_state.get_tile(row_index, column_index + 1)

                    if TileFitter.fits(tile_to_play.turn(tile_turns),
                                       top=top,
                                       bottom=bottom,
                                       left=left,
                                       right=right,
                                       game_state=game_state):
                        playing_positions.append(
                            PlayingPosition(coordinate=Coordinate(
                                row=row_index, column=column_index),
                                            turns=tile_turns))

        return playing_positions
 def get_river_rotation(cls, game_state: CarcassonneGameState, tile: Tile) -> Rotation:
     if tile.has_river() and game_state.last_tile_action is not None:
         river_rotation: Rotation = cls.get_river_rotation_tile(
             previous_tile=game_state.last_tile_action.tile,
             new_tile=tile)
         if river_rotation != Rotation.NONE:
             return river_rotation
         else:
             return game_state.last_river_rotation
示例#3
0
 def roads_fit(cls,
               center: Tile,
               top: Tile = None,
               right: Tile = None,
               bottom: Tile = None,
               left: Tile = None) -> bool:
     for side in center.get_road_ends():
         if side == Side.LEFT and left is not None and not left.get_road_ends(
         ).__contains__(Side.RIGHT):
             return False
         if side == Side.RIGHT and right is not None and not right.get_road_ends(
         ).__contains__(Side.LEFT):
             return False
         if side == Side.TOP and top is not None and not top.get_road_ends(
         ).__contains__(Side.BOTTOM):
             return False
         if side == Side.BOTTOM and bottom is not None and not bottom.get_road_ends(
         ).__contains__(Side.TOP):
             return False
     return True
示例#4
0
from wingedsheep.carcassonne.objects.farmer_connection import FarmerConnection
from wingedsheep.carcassonne.objects.farmer_side import FarmerSide
from wingedsheep.carcassonne.objects.side import Side
from wingedsheep.carcassonne.objects.tile import Tile

the_river_tiles = {
    "river_start":
    Tile(description="river_start",
         river=[
             Connection(Side.CENTER, Side.BOTTOM),
         ],
         grass=[Side.LEFT, Side.RIGHT, Side.TOP],
         farms=[
             FarmerConnection(farmer_positions=[
                 Side.TOP_LEFT, Side.TOP_RIGHT, Side.BOTTOM_LEFT,
                 Side.BOTTOM_RIGHT
             ],
                              tile_connections=[
                                  FarmerSide.TLL, FarmerSide.TLT,
                                  FarmerSide.TRT, FarmerSide.TRR,
                                  FarmerSide.BRR, FarmerSide.BRB,
                                  FarmerSide.BLB, FarmerSide.BLL
                              ])
         ],
         image=os.path.join("the_river", "River_III_C2_Tile_A.png")),
    "river_city_with_road":
    Tile(
        description="river_city_with_road",
        river=[
            Connection(Side.LEFT, Side.RIGHT),
        ],
        road=[
import os

from wingedsheep.carcassonne.objects.connection import Connection
from wingedsheep.carcassonne.objects.farmer_connection import FarmerConnection
from wingedsheep.carcassonne.objects.farmer_side import FarmerSide
from wingedsheep.carcassonne.objects.side import Side
from wingedsheep.carcassonne.objects.tile import Tile

inns_and_cathedrals_tiles = {
    "ic_1":
    Tile(description="ic_1",
         grass=[Side.TOP],
         city=[[Side.LEFT, Side.BOTTOM], [Side.RIGHT]],
         farms=[
             FarmerConnection(
                 farmer_positions=[Side.TOP_LEFT, Side.TOP_RIGHT],
                 tile_connections=[FarmerSide.TLT, FarmerSide.TRT],
                 city_sides=[Side.LEFT, Side.RIGHT, Side.BOTTOM])
         ],
         shield=True,
         image=os.path.join("inns_and_cathedrals", "inns_cathedrals_1.png")),
    "ic_2":
    Tile(description="ic_2",
         grass=[Side.TOP, Side.RIGHT],
         road=[Connection(Side.BOTTOM, Side.LEFT)],
         farms=[
             FarmerConnection(farmer_positions=[
                 Side.TOP_LEFT, Side.TOP_RIGHT, Side.BOTTOM_RIGHT
             ],
                              tile_connections=[
                                  FarmerSide.TLL, FarmerSide.TLT,
 def get_river_rotation_tile(cls, previous_tile: Tile, new_tile: Tile):
     previous_river_ends: Set[Side] = set(previous_tile.get_river_ends())
     river_ends: Set[Side] = set(new_tile.get_river_ends())
     return cls.get_river_rotation_ends(previous_river_ends=previous_river_ends, river_ends=river_ends)
示例#7
0
    def rivers_fit(cls,
                   center: Tile,
                   top: Tile = None,
                   right: Tile = None,
                   bottom: Tile = None,
                   left: Tile = None,
                   game_state: CarcassonneGameState = None) -> bool:
        if len(center.get_river_ends()) == 0:
            return True

        connected_side = None
        unconnected_side = None

        for side in center.get_river_ends():
            if side == Side.LEFT and left is not None and left.get_river_ends(
            ).__contains__(Side.RIGHT):
                connected_side = Side.LEFT
            if side == Side.RIGHT and right is not None and right.get_river_ends(
            ).__contains__(Side.LEFT):
                connected_side = Side.RIGHT
            if side == Side.TOP and top is not None and top.get_river_ends(
            ).__contains__(Side.BOTTOM):
                connected_side = Side.TOP
            if side == Side.BOTTOM and bottom is not None and bottom.get_river_ends(
            ).__contains__(Side.TOP):
                connected_side = Side.BOTTOM

            if side == Side.LEFT and left is None:
                unconnected_side = Side.LEFT
            if side == Side.RIGHT and right is None:
                unconnected_side = Side.RIGHT
            if side == Side.TOP and top is None:
                unconnected_side = Side.TOP
            if side == Side.BOTTOM and bottom is None:
                unconnected_side = Side.BOTTOM

            if side == Side.LEFT and left is not None and not left.get_river_ends(
            ).__contains__(Side.RIGHT):
                return False
            if side == Side.RIGHT and right is not None and not right.get_river_ends(
            ).__contains__(Side.LEFT):
                return False
            if side == Side.TOP and top is not None and not top.get_river_ends(
            ).__contains__(Side.BOTTOM):
                return False
            if side == Side.BOTTOM and bottom is not None and not bottom.get_river_ends(
            ).__contains__(Side.TOP):
                return False

        if connected_side is None:
            return False

        if unconnected_side is not None and game_state.last_river_rotation is not Rotation.NONE and game_state.last_tile_action is not None:
            last_played_tile: Tile = game_state.last_tile_action.tile
            last_played_river_ends: Set[
                Side] = last_played_tile.get_river_ends()
            river_ends: Set[Side] = {connected_side, unconnected_side}

            rotation: Rotation = RiverRotationUtil.get_river_rotation_ends(
                previous_river_ends=last_played_river_ends,
                river_ends=river_ends)
            if rotation == game_state.last_river_rotation:
                return False

        return True