|
9 | 9 |
|
10 | 10 | from __future__ import annotations |
11 | 11 |
|
12 | | -from game.card import Card |
13 | 12 | from enum import Enum |
| 13 | +from typing import Optional |
| 14 | + |
| 15 | +from game.card import Card |
14 | 16 |
|
15 | 17 |
|
16 | 18 | class ActionSource(Enum): |
@@ -50,28 +52,28 @@ class Action: |
50 | 52 | """ |
51 | 53 |
|
52 | 54 | action_type: ActionType |
53 | | - card: Card |
54 | | - target: Card |
| 55 | + card: Optional[Card] |
| 56 | + target: Optional[Card] |
55 | 57 | played_by: int |
56 | 58 | requires_additional_input: bool |
57 | 59 | source: ActionSource |
58 | 60 |
|
59 | 61 | def __init__( |
60 | 62 | self, |
61 | 63 | action_type: ActionType, |
62 | | - card: Card, |
63 | | - target: Card, |
64 | 64 | played_by: int, |
| 65 | + card: Optional[Card] = None, |
| 66 | + target: Optional[Card] = None, |
65 | 67 | requires_additional_input: bool = False, |
66 | 68 | source: ActionSource = ActionSource.HAND, |
67 | 69 | ): |
68 | 70 | """Initialize a new Action instance. |
69 | 71 |
|
70 | 72 | Args: |
71 | 73 | action_type (ActionType): The type of action being performed. |
72 | | - card (Card): The card being played or used. |
73 | | - target (Card): The target card (if any) for the action. |
74 | 74 | played_by (int): Index of the player performing the action (0 or 1). |
| 75 | + card (Optional[Card], optional): The card being played or used. Defaults to None. |
| 76 | + target (Optional[Card], optional): The target card (if any) for the action. Defaults to None. |
75 | 77 | requires_additional_input (bool, optional): Whether more input is needed. |
76 | 78 | Defaults to False. |
77 | 79 | source (ActionSource, optional): Where the card comes from. |
@@ -107,15 +109,27 @@ def __repr__(self) -> str: |
107 | 109 | elif self.action_type == ActionType.ONE_OFF: |
108 | 110 | return f"Play {self.card} as one-off" |
109 | 111 | elif self.action_type == ActionType.SCUTTLE: |
110 | | - return f"Scuttle {self.target} on P{self.target.played_by}'s field with {self.card}" |
| 112 | + target_str = str(self.target) if self.target else "None" |
| 113 | + card_str = str(self.card) if self.card else "None" |
| 114 | + target_player = self.target.played_by if self.target else '?' |
| 115 | + return f"Scuttle {target_str} on P{target_player}'s field with {card_str}" |
111 | 116 | elif self.action_type == ActionType.DRAW: |
112 | 117 | return "Draw a card from deck" |
113 | 118 | elif self.action_type == ActionType.COUNTER: |
114 | | - return f"Counter {self.target} with {self.card}" |
| 119 | + target_str = str(self.target) if self.target else "None" |
| 120 | + card_str = str(self.card) if self.card else "None" |
| 121 | + return f"Counter {target_str} with {card_str}" |
115 | 122 | elif self.action_type == ActionType.JACK: |
116 | | - return f"Play {self.card} as jack on {self.target}" |
| 123 | + target_str = str(self.target) if self.target else "None" |
| 124 | + card_str = str(self.card) if self.card else "None" |
| 125 | + return f"Play {card_str} as jack on {target_str}" |
117 | 126 | elif self.action_type == ActionType.RESOLVE: |
118 | | - return f"Resolve one-off {self.target}" |
| 127 | + target_str = str(self.target) if self.target else "None" |
| 128 | + return f"Resolve one-off {target_str}" |
| 129 | + else: |
| 130 | + # Handle any unexpected action types |
| 131 | + card_str = str(self.card) if self.card else "None" |
| 132 | + return f"Unknown Action: {self.action_type.value} with card {card_str}" |
119 | 133 |
|
120 | 134 | def __str__(self) -> str: |
121 | 135 | """Get a string representation of the action. |
|
0 commit comments