Skip to content
Merged
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "socha"
version = "1.0.3"
version = "1.0.4"
authors = [
{ name = "FalconsSky", email = "stu222782@mail.uni-kiel.de" },
]
Expand Down
18 changes: 0 additions & 18 deletions setup.py

This file was deleted.

5 changes: 4 additions & 1 deletion socha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from socha.api.networking.game_client import IClientHandler
from socha.api.plugin.penguins import *
from socha.api.plugin.penguins.game_state import GameState
from socha.api.plugin.penguins.coordinate import *
from socha.api.plugin.penguins.board import *
from socha.api.plugin.penguins.team import *
from socha.api.protocol.protocol import Result
from socha.starter import Starter

Expand Down
22 changes: 13 additions & 9 deletions socha/api/networking/game_client.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""
This module handels the communication with the api and the students logic.
"""
import gc
import logging
import sys
import time
from typing import List, Union

from socha.api.networking.xml_protocol_interface import XMLProtocolInterface
from socha.api.plugin import penguins
from socha.api.plugin.penguins import Field, GameState, Move, CartesianCoordinate, TeamEnum, Penguin, HexCoordinate
from socha.api.plugin.penguins import game_state
from socha.api.plugin.penguins.board import Field, Move, CartesianCoordinate, TeamEnum, Penguin, HexCoordinate
from socha.api.plugin.penguins.game_state import GameState
from socha.api.protocol.protocol import State, Board, Data, \
Error, From, Join, Joined, JoinPrepared, JoinRoom, To, Team, Room, Result, MoveRequest, Left, Errorpacket
from socha.api.protocol.protocol_packet import ProtocolPacket


def _convert_board(protocol_board: Board) -> penguins.Board:
def _convert_board(protocol_board: Board) -> game_state.Board:
"""
Converts a protocol Board to a usable game board for using in the logic.
:param protocol_board: A Board object in protocol format
Expand All @@ -39,7 +41,7 @@ def _convert_board(protocol_board: Board) -> penguins.Board:
else:
raise ValueError(f"Invalid field value {fields_value} at coordinates {coordinate}")

return penguins.Board(board_list)
return game_state.Board(board_list)


class IClientHandler:
Expand Down Expand Up @@ -204,7 +206,7 @@ def _on_state(self, message):
last_move = Move(team_enum=last_game_state.current_team.name,
from_value=from_value,
to_value=to_value)
game_state = last_game_state.perform_move(last_move)
_game_state = last_game_state.perform_move(last_move)
else:
first_team = Team(TeamEnum.ONE,
fish=0 if not last_game_state else last_game_state.first_team.fish,
Expand All @@ -214,16 +216,18 @@ def _on_state(self, message):
0 if not last_game_state else last_game_state.second_team.fish,
penguins=[] if not last_game_state else last_game_state.second_team.penguins,
moves=[] if not last_game_state else last_game_state.second_team.moves)
first_team.opponent = second_team
second_team.opponent = first_team

game_state = GameState(
_game_state = GameState(
board=_convert_board(message.data.class_binding.board),
turn=message.data.class_binding.turn,
first_team=first_team,
second_team=second_team,
last_move=None,
)
self._game_handler.history[-1].append(game_state)
self._game_handler.on_update(game_state)
self._game_handler.history[-1].append(_game_state)
self._game_handler.on_update(_game_state)

def start(self):
"""
Expand Down Expand Up @@ -278,7 +282,6 @@ def _client_loop(self):
The client loop is the main loop, where the client waits for messages from the server
and handles them accordingly.
"""

while self.running:
if self.network_interface.connected:
response = self._receive()
Expand All @@ -290,6 +293,7 @@ def _client_loop(self):
self._handle_left()
else:
self._on_object(response)
gc.collect()
elif self.running:
logging.error(f"Received a object of unknown class: {response}")
raise NotImplementedError("Received object of unknown class.")
Expand Down
2 changes: 1 addition & 1 deletion socha/api/networking/xml_protocol_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from xsdata.formats.dataclass.serializers.config import SerializerConfig

from socha.api.networking.network_socket import NetworkSocket
from socha.api.plugin.penguins import Move, TeamEnum
from socha.api.plugin.penguins.team import TeamEnum, Move
from socha.api.protocol.protocol import *


Expand Down
Loading