-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09e64ff
commit 621a9a4
Showing
11 changed files
with
166 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .eventmanager import Eventmanager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from . import events | ||
import logging | ||
|
||
|
||
class Eventmanager: | ||
def __init__(self, conversation): | ||
self.conversation = conversation | ||
|
||
def registered_events(self): | ||
return events.BaseEvent.__subclasses__() | ||
|
||
def handle_events(self, board, game): | ||
logging.info(f"Checking events: {self.registered_events()}") | ||
for event_class in self.registered_events(): | ||
event = event_class() | ||
if event.is_triggering(board, game): | ||
logging.info(f"triggering event {event}") | ||
if event.is_sending_to_player(): | ||
self.conversation.send_to_player(event.react_with(board, game)) | ||
else: | ||
self.conversation.send_to_spectator(event.react_with(board, game)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .base_event import BaseEvent | ||
from .game_start import GameStartEvent | ||
from .game_end import GameEndEvent | ||
from .queen_won import QueenWonEvent | ||
from .queen_lost import QueenLostEvent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class BaseEvent: | ||
def __init__(self): | ||
pass | ||
|
||
def is_triggering(self, board, game): | ||
return False | ||
|
||
def is_sending_to_player(self): | ||
return True | ||
|
||
def react_with(self, board, game): | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .base_event import BaseEvent | ||
import chess | ||
|
||
|
||
class GameEndEvent(BaseEvent): | ||
def __init__(self): | ||
pass | ||
|
||
def is_triggering(self, board: chess.Board, game): | ||
return board.is_game_over() or game.state["status"] != "started" | ||
|
||
def react_with(self, board, game): | ||
return f"This was a nice game. Feel free to challenge me anytime. Thanks for playing!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .base_event import BaseEvent | ||
import chess | ||
|
||
|
||
class GameStartEvent(BaseEvent): | ||
def __init__(self): | ||
pass | ||
|
||
def is_triggering(self, board: chess.Board, game): | ||
return len(board.move_stack) <= 1 | ||
|
||
def react_with(self, board, game): | ||
return "Hello, nice to meet you! Have fun and good luck! :)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .base_event import BaseEvent | ||
import chess | ||
import logging | ||
|
||
|
||
class QueenLostEvent(BaseEvent): | ||
def __init__(self): | ||
pass | ||
|
||
def is_triggering(self, board: chess.Board, game): | ||
old_board = board.copy() | ||
move = old_board.pop() | ||
if len(old_board.pieces(chess.QUEEN, game.is_white)) > len( | ||
board.pieces(chess.QUEEN, game.is_white) | ||
): | ||
return True | ||
return False | ||
|
||
def react_with(self, board: chess.Board, game): | ||
return f"(ノಠ益ಠ)ノ彡┻━┻ NO, MY QUEEN!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .base_event import BaseEvent | ||
import chess | ||
import logging | ||
|
||
|
||
class QueenWonEvent(BaseEvent): | ||
def __init__(self): | ||
pass | ||
|
||
def is_triggering(self, board: chess.Board, game): | ||
old_board = board.copy() | ||
move = old_board.pop() | ||
if len(old_board.pieces(chess.QUEEN, not game.is_white)) > len( | ||
board.pieces(chess.QUEEN, not game.is_white) | ||
): | ||
return True | ||
return False | ||
|
||
def react_with(self, board: chess.Board, game): | ||
return f"Ah, the Botez Gambit. Classic." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters