|
| 1 | +from abc import ABC |
| 2 | +from dataclasses import dataclass |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +from src.entities.Card import Card |
| 6 | +from ..entities.AllResources import AllResources |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from src.Game import Game |
| 10 | +from .Move import Move |
| 11 | + |
| 12 | + |
| 13 | +@dataclass(slots=True, frozen=True) |
| 14 | +class Build(Move, ABC): |
| 15 | + @staticmethod |
| 16 | + def _build(game: "Game", card: Card) -> "Game": |
| 17 | + current_player = game.current_player |
| 18 | + gold_paid_for_red = max(0, card.cost.red - current_player.production.red - current_player.resources.red) |
| 19 | + gold_paid_for_green = max(0, card.cost.green - current_player.production.green - current_player.resources.green) |
| 20 | + gold_paid_for_blue = max(0, card.cost.blue - current_player.production.blue - current_player.resources.blue) |
| 21 | + gold_paid_for_black = max(0, card.cost.black - current_player.production.black - current_player.resources.black) |
| 22 | + gold_paid_for_white = max(0, card.cost.white - current_player.production.white - current_player.resources.white) |
| 23 | + cost = AllResources( |
| 24 | + max(0, card.cost.red - current_player.production.red - gold_paid_for_red), |
| 25 | + max(0, card.cost.green - current_player.production.green - gold_paid_for_green), |
| 26 | + max(0, card.cost.blue - current_player.production.blue - gold_paid_for_blue), |
| 27 | + max(0, card.cost.black - current_player.production.black - gold_paid_for_black), |
| 28 | + max(0, card.cost.white - current_player.production.white - gold_paid_for_white), |
| 29 | + sum((gold_paid_for_red, gold_paid_for_green, gold_paid_for_blue, gold_paid_for_black, gold_paid_for_white)), |
| 30 | + ) |
| 31 | + current_player.resources = AllResources( |
| 32 | + max(0, current_player.resources.red - cost.red), |
| 33 | + max(0, current_player.resources.green - cost.green), |
| 34 | + max(0, current_player.resources.blue - cost.blue), |
| 35 | + max(0, current_player.resources.black - cost.black), |
| 36 | + max(0, current_player.resources.white - cost.white), |
| 37 | + current_player.resources.gold - cost.gold, |
| 38 | + ) |
| 39 | + game.board.resources = AllResources( |
| 40 | + game.board.resources.red + cost.red, |
| 41 | + game.board.resources.green + cost.green, |
| 42 | + game.board.resources.blue + cost.blue, |
| 43 | + game.board.resources.black + cost.black, |
| 44 | + game.board.resources.white + cost.white, |
| 45 | + game.board.resources.gold + cost.gold, |
| 46 | + ) |
| 47 | + current_player.cards.append(card) |
| 48 | + return game |
0 commit comments