Skip to content

Commit

Permalink
Merge pull request #4 from wingedsheep/feature/2_add_farmers
Browse files Browse the repository at this point in the history
Feature/2 add farmers
  • Loading branch information
wingedsheep committed May 19, 2020
2 parents fedeb85 + 5d34e74 commit 9d1aecd
Show file tree
Hide file tree
Showing 41 changed files with 1,891 additions and 470 deletions.
16 changes: 8 additions & 8 deletions examples/four_player_game_random_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ def print_state(carcassonne_game_state: CarcassonneGameState):
},
"meeples": {
"player 1": {
"normal": str(carcassonne_game_state.meeples[0]) + " / " + str(carcassonne_game_state.meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL, game.state.placed_meeples[0])))),
"normal": str(carcassonne_game_state.meeples[0]) + " / " + str(carcassonne_game_state.meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[0])))),
"abbots": str(carcassonne_game_state.abbots[0]) + " / " + str(carcassonne_game_state.abbots[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[0])))),
"big": str(carcassonne_game_state.big_meeples[0]) + " / " + str(carcassonne_game_state.big_meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG, game.state.placed_meeples[0]))))
"big": str(carcassonne_game_state.big_meeples[0]) + " / " + str(carcassonne_game_state.big_meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[0]))))
},
"player 2": {
"normal": str(carcassonne_game_state.meeples[1]) + " / " + str(carcassonne_game_state.meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL, game.state.placed_meeples[1])))),
"normal": str(carcassonne_game_state.meeples[1]) + " / " + str(carcassonne_game_state.meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[1])))),
"abbots": str(carcassonne_game_state.abbots[1]) + " / " + str(carcassonne_game_state.abbots[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[1])))),
"big": str(carcassonne_game_state.big_meeples[1]) + " / " + str(carcassonne_game_state.big_meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG, game.state.placed_meeples[1]))))
"big": str(carcassonne_game_state.big_meeples[1]) + " / " + str(carcassonne_game_state.big_meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[1]))))
},
"player 3": {
"normal": str(carcassonne_game_state.meeples[2]) + " / " + str(carcassonne_game_state.meeples[2] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL, game.state.placed_meeples[2])))),
"normal": str(carcassonne_game_state.meeples[2]) + " / " + str(carcassonne_game_state.meeples[2] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[2])))),
"abbots": str(carcassonne_game_state.abbots[2]) + " / " + str(carcassonne_game_state.abbots[2] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[2])))),
"big": str(carcassonne_game_state.big_meeples[2]) + " / " + str(carcassonne_game_state.big_meeples[2] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG, game.state.placed_meeples[2]))))
"big": str(carcassonne_game_state.big_meeples[2]) + " / " + str(carcassonne_game_state.big_meeples[2] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[2]))))
},
"player 4": {
"normal": str(carcassonne_game_state.meeples[3]) + " / " + str(carcassonne_game_state.meeples[3] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL, game.state.placed_meeples[3])))),
"normal": str(carcassonne_game_state.meeples[3]) + " / " + str(carcassonne_game_state.meeples[3] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[3])))),
"abbots": str(carcassonne_game_state.abbots[3]) + " / " + str(carcassonne_game_state.abbots[3] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[3])))),
"big": str(carcassonne_game_state.big_meeples[3]) + " / " + str(carcassonne_game_state.big_meeples[3] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG, game.state.placed_meeples[3]))))
"big": str(carcassonne_game_state.big_meeples[3]) + " / " + str(carcassonne_game_state.big_meeples[3] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[3]))))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/two_player_game_random_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def print_state(carcassonne_game_state: CarcassonneGameState):
},
"meeples": {
"player 1": {
"normal": str(carcassonne_game_state.meeples[0]) + " / " + str(carcassonne_game_state.meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL, game.state.placed_meeples[0])))),
"normal": str(carcassonne_game_state.meeples[0]) + " / " + str(carcassonne_game_state.meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[0])))),
"abbots": str(carcassonne_game_state.abbots[0]) + " / " + str(carcassonne_game_state.abbots[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[0])))),
"big": str(carcassonne_game_state.big_meeples[0]) + " / " + str(carcassonne_game_state.big_meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG, game.state.placed_meeples[0]))))
"big": str(carcassonne_game_state.big_meeples[0]) + " / " + str(carcassonne_game_state.big_meeples[0] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[0]))))
},
"player 2": {
"normal": str(carcassonne_game_state.meeples[1]) + " / " + str(carcassonne_game_state.meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL, game.state.placed_meeples[1])))),
"normal": str(carcassonne_game_state.meeples[1]) + " / " + str(carcassonne_game_state.meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.NORMAL or x.meeple_type == MeepleType.FARMER, game.state.placed_meeples[1])))),
"abbots": str(carcassonne_game_state.abbots[1]) + " / " + str(carcassonne_game_state.abbots[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.ABBOT, game.state.placed_meeples[1])))),
"big": str(carcassonne_game_state.big_meeples[1]) + " / " + str(carcassonne_game_state.big_meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG, game.state.placed_meeples[1]))))
"big": str(carcassonne_game_state.big_meeples[1]) + " / " + str(carcassonne_game_state.big_meeples[1] + len(list(filter(lambda x: x.meeple_type == MeepleType.BIG or x.meeple_type == MeepleType.BIG_FARMER, game.state.placed_meeples[1]))))
}
}
}
Expand Down
Empty file removed main/agent/__init__.py
Empty file.
42 changes: 0 additions & 42 deletions main/agent/random_agent.py

This file was deleted.

5 changes: 2 additions & 3 deletions main/carcassonne_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
class CarcassonneGame:

def __init__(self,
players: object = 2,
tile_sets: object = (TileSet.BASE, TileSet.THE_RIVER, TileSet.INNS_AND_CATHEDRALS)):
players: int = 2,
tile_sets: [TileSet] = (TileSet.BASE, TileSet.THE_RIVER, TileSet.INNS_AND_CATHEDRALS)):
self.players = players
self.tile_sets = tile_sets
self.state: CarcassonneGameState = CarcassonneGameState(tile_sets=tile_sets, players=players)
self.visualiser = CarcassonneVisualiser()
self.action_util = ActionUtil()

def reset(self):
self.state = CarcassonneGameState(tile_sets=self.tile_sets)
Expand Down
8 changes: 0 additions & 8 deletions main/carcassonne_game_definition.py

This file was deleted.

51 changes: 0 additions & 51 deletions main/carcassonne_game_player.py

This file was deleted.

13 changes: 1 addition & 12 deletions main/carcassonne_game_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,15 @@

from main.objects.actions.tile_action import TileAction
from main.objects.coordinate import Coordinate
from main.objects.game_phase import GamePhase
from main.tile_sets.base_deck import base_tile_counts, base_tiles
from main.tile_sets.inns_and_cathedrals_deck import inns_and_cathedrals_tile_counts, inns_and_cathedrals_tiles
from main.tile_sets.the_river_deck import the_river_tiles, the_river_tile_counts
from main.objects.playing_position import PlayingPosition
from main.objects.rotation import Rotation
from main.objects.tile import Tile
from main.tile_sets.tile_sets import TileSet


class GamePhase(Enum):
TILES = "tiles"
MEEPLES = "meeples"

def to_json(self):
return self.value

def __str__(self):
return self.value


class CarcassonneGameState:

def __init__(
Expand Down
14 changes: 12 additions & 2 deletions main/carcassonne_visualiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ class CarcassonneVisualiser:
Side.RIGHT: (tile_size - (meeple_size / 2) - 3, tile_size / 2),
Side.BOTTOM: (tile_size / 2, tile_size - (meeple_size / 2) - 3),
Side.LEFT: ((meeple_size / 2) + 3, tile_size / 2),
Side.CENTER: (tile_size / 2, tile_size / 2)
Side.CENTER: (tile_size / 2, tile_size / 2),
Side.TOP_LEFT: (tile_size / 4, (meeple_size / 2) + 3),
Side.TOP_RIGHT: ((tile_size / 4) * 3, (meeple_size / 2) + 3),
Side.BOTTOM_LEFT: (tile_size / 4, tile_size - (meeple_size / 2) - 3),
Side.BOTTOM_RIGHT: ((tile_size / 4) * 3, tile_size - (meeple_size / 2) - 3)
}

big_meeple_position_offsets = {
Side.TOP: (tile_size / 2, (big_meeple_size / 2) + 3),
Side.RIGHT: (tile_size - (big_meeple_size / 2) - 3, tile_size / 2),
Side.BOTTOM: (tile_size / 2, tile_size - (big_meeple_size / 2) - 3),
Side.LEFT: ((big_meeple_size / 2) + 3, tile_size / 2),
Side.CENTER: (tile_size / 2, tile_size / 2)
Side.CENTER: (tile_size / 2, tile_size / 2),
Side.TOP_LEFT: (tile_size / 4, (big_meeple_size / 2) + 3),
Side.TOP_RIGHT: ((tile_size / 4) * 3, (big_meeple_size / 2) + 3),
Side.BOTTOM_LEFT: (tile_size / 4, tile_size - (big_meeple_size / 2) - 3),
Side.BOTTOM_RIGHT: ((tile_size / 4) * 3, tile_size - (big_meeple_size / 2) - 3)
}

def __init__(self):
Expand Down Expand Up @@ -102,4 +110,6 @@ def __get_image(self, player: int, meeple_type: MeepleType):
elif meeple_type == MeepleType.BIG:
return ImageTk.PhotoImage(Image.open(abs_file_path).resize((self.big_meeple_size, self.big_meeple_size), Image.ANTIALIAS))
elif meeple_type == MeepleType.FARMER:
return ImageTk.PhotoImage(Image.open(abs_file_path).resize((self.meeple_size, self.meeple_size), Image.ANTIALIAS).rotate(-90))
elif meeple_type == MeepleType.BIG_FARMER:
return ImageTk.PhotoImage(Image.open(abs_file_path).resize((self.big_meeple_size, self.big_meeple_size), Image.ANTIALIAS).rotate(-90))
6 changes: 6 additions & 0 deletions main/objects/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ def to_json(self):

def __str__(self):
return json.dumps(self.to_json(), indent=2)

def __eq__(self, other):
return self.a == other.a and self.b == other.b

def __hash__(self):
return hash((self.a, self.b))
16 changes: 16 additions & 0 deletions main/objects/coordinate_with_farmer_side.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from main.objects.coordinate import Coordinate
from main.objects.farmer_side import FarmerSide
from main.objects.side import Side


class CoordinateWithFarmerSide:

def __init__(self, coordinate: Coordinate, farmer_side: FarmerSide):
self.coordinate = coordinate
self.farmer_side = farmer_side

def __eq__(self, other):
return self.coordinate == other.coordinate and self.farmer_side == other.farmer_side

def __hash__(self):
return hash((self.coordinate, self.farmer_side))
6 changes: 6 additions & 0 deletions main/objects/farm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from main.objects.farmer_connection_with_coordinate import FarmerConnectionWithCoordinate


class Farm:
def __init__(self, farmer_connections_with_coordinate: [FarmerConnectionWithCoordinate]):
self.farmer_connections_with_coordinate: [FarmerConnectionWithCoordinate] = farmer_connections_with_coordinate
29 changes: 29 additions & 0 deletions main/objects/farmer_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json

from main.objects.farmer_side import FarmerSide
from main.objects.side import Side


class FarmerConnection:
def __init__(self, farmer_positions: [Side], tile_connections: [FarmerSide] = (), city_sides: [Side] = ()):
self.farmer_positions: [Side] = farmer_positions
self.tile_connections: [FarmerSide] = tile_connections
self.city_sides: [Side] = city_sides

def to_json(self):
return {
"farmer_position": self.farmer_positions.to_json(),
"tile_connections": self.tile_connections.to_json(),
"city_sides": self.city_sides.to_json()
}

def __str__(self):
return json.dumps(self.to_json(), indent=2)

def __eq__(self, other):
return self.farmer_positions == other.farmer_positions \
and self.tile_connections == other.tile_connections \
and self.city_sides == other.city_sides

def __hash__(self):
return hash((tuple(self.farmer_positions), tuple(self.tile_connections), tuple(self.city_sides)))
19 changes: 19 additions & 0 deletions main/objects/farmer_connection_with_coordinate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json

from main.objects.coordinate import Coordinate
from main.objects.farmer_connection import FarmerConnection
from main.objects.farmer_side import FarmerSide
from main.objects.side import Side


class FarmerConnectionWithCoordinate:
def __init__(self, farmer_connection: FarmerConnection, coordinate: Coordinate = ()):
self.farmer_connection: FarmerConnection = farmer_connection
self.coordinate: Coordinate = coordinate

def __eq__(self, other):
return self.farmer_connection == other.farmer_connection \
and self.coordinate == other.coordinate

def __hash__(self):
return hash((self.farmer_connection, self.coordinate))
30 changes: 30 additions & 0 deletions main/objects/farmer_side.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from enum import Enum

from main.objects.side import Side


class FarmerSide(Enum):
TLL = "tll"
TLT = "tlt"
TRT = "trt"
TRR = "trr"
BLL = "bll"
BLB = "blb"
BRB = "brb"
BRR = "brr"

def to_json(self):
return self.value

def __str__(self):
return self.value

def get_side(self) -> Side:
if self.value[2] == "l":
return Side.LEFT
if self.value[2] == "r":
return Side.RIGHT
if self.value[2] == "b":
return Side.BOTTOM
if self.value[2] == "t":
return Side.TOP
12 changes: 12 additions & 0 deletions main/objects/game_phase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from enum import Enum


class GamePhase(Enum):
TILES = "tiles"
MEEPLES = "meeples"

def to_json(self):
return self.value

def __str__(self):
return self.value
6 changes: 6 additions & 0 deletions main/objects/side.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class Side(Enum):
LEFT = "left"
CENTER = "center"

# special for farmers
TOP_LEFT = "top_left"
TOP_RIGHT = "top_right"
BOTTOM_LEFT = "bottom_left"
BOTTOM_RIGHT = "bottom_right"

def to_json(self):
return self.value

Expand Down
Loading

0 comments on commit 9d1aecd

Please sign in to comment.