renamed some directory to avoid conflit and improve readability
This commit is contained in:
parent
82fc77cc6e
commit
b902d83d90
13 changed files with 19 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -127,6 +127,7 @@ dmypy.json
|
||||||
|
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
/.idea/
|
||||||
/.idea/.gitignore
|
/.idea/.gitignore
|
||||||
/.idea/discord.xml
|
/.idea/discord.xml
|
||||||
/.idea/markdown.xml
|
/.idea/markdown.xml
|
||||||
|
|
3
main.pyw
3
main.pyw
|
@ -6,8 +6,7 @@ from gui.scene import HelloWorldScene, FPSCounterScene
|
||||||
# Créer une fenêtre
|
# Créer une fenêtre
|
||||||
window = Window(resizable=True, visible=False)
|
window = Window(resizable=True, visible=False)
|
||||||
|
|
||||||
window.add_scene(HelloWorldScene())
|
window.add_scene(HelloWorldScene(), FPSCounterScene())
|
||||||
window.add_scene(FPSCounterScene())
|
|
||||||
|
|
||||||
# Lance la fenêtre
|
# Lance la fenêtre
|
||||||
window.set_visible(True)
|
window.set_visible(True)
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from src import Boat
|
from source import Boat
|
||||||
from src.enum import Orientation, BombState
|
from source.enums import Orientation, BombState
|
||||||
from src.error import InvalidBoatPosition, PositionAlreadyShot
|
from source.error import InvalidBoatPosition, PositionAlreadyShot
|
||||||
from src.utils import copy_array_offset
|
from source.utils import copy_array_offset
|
||||||
|
|
||||||
|
|
||||||
class Board:
|
class Board:
|
||||||
__slots__ = ("width", "height", "_boats", "_bombs")
|
__slots__ = ("_width", "_height", "_boats", "_bombs")
|
||||||
|
|
||||||
def __init__(self, width: int, height: int = None) -> None:
|
def __init__(self, width: int, height: int = None) -> None:
|
||||||
self.width: int = width
|
self._width: int = width
|
||||||
self.height: int = width if height is None else height
|
self._height: int = width if height is None else height
|
||||||
self._boats: dict[Boat, tuple[int, int]] = {} # associate the boats to their position
|
self._boats: dict[Boat, tuple[int, int]] = {} # associate the boats to their position
|
||||||
self._bombs: np.array = np.ones((self.width, self.height), dtype=np.bool_)
|
self._bombs: np.array = np.ones((self._width, self._height), dtype=np.bool_)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"<{self.__class__.__name__} width={self.width}, height={self.height}>"
|
return f"<{self.__class__.__name__} width={self._width}, height={self._height}>"
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return str(self.get_matrice())
|
return str(self.get_matrice())
|
||||||
|
@ -30,21 +30,22 @@ class Board:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# get the sum of the boat
|
# get the sum of the boat
|
||||||
boat_sum: int = boat.get_matrice().sum()
|
boat_mat: np.array = boat.get_matrice()
|
||||||
|
boat_mat_sum: int = boat_mat.sum()
|
||||||
|
|
||||||
# get the old board matrice sum
|
# get the old board matrice sum
|
||||||
board_mat: np.array = self.get_matrice()
|
board_mat: np.array = self.get_matrice()
|
||||||
board_mat_sum_old: int = board_mat.sum()
|
board_mat_sum_old: int = board_mat.sum()
|
||||||
|
|
||||||
# add the boat to the board matrice
|
# add the boat to the board matrice
|
||||||
copy_array_offset(boat.get_matrice(), board_mat, offset=position)
|
copy_array_offset(boat_mat, board_mat, offset=position)
|
||||||
|
|
||||||
# get the new board matrice sum
|
# get the new board matrice sum
|
||||||
board_mat_sum_new: int = board_mat.sum()
|
board_mat_sum_new: int = board_mat.sum()
|
||||||
|
|
||||||
# if the sum of the old board plus the boat sum is different from the new board sum,
|
# if the sum of the old board plus the boat sum is different from the new board sum,
|
||||||
# then the boat have been incorrectly placed (overlapping, outside of bounds, ...)
|
# then the boat have been incorrectly placed (overlapping, outside of bounds, ...)
|
||||||
if board_mat_sum_old + boat_sum != board_mat_sum_new: raise InvalidBoatPosition(boat, position)
|
if board_mat_sum_old + boat_mat_sum != board_mat_sum_new: raise InvalidBoatPosition(boat, position)
|
||||||
|
|
||||||
# otherwise accept the boat in the boats dict
|
# otherwise accept the boat in the boats dict
|
||||||
self._boats[boat] = position
|
self._boats[boat] = position
|
||||||
|
@ -94,7 +95,7 @@ class Board:
|
||||||
"""
|
"""
|
||||||
:return: the boat represented as a matrice
|
:return: the boat represented as a matrice
|
||||||
"""
|
"""
|
||||||
board = np.zeros((self.width, self.height), dtype=np.ushort)
|
board = np.zeros((self._width, self._height), dtype=np.ushort)
|
||||||
|
|
||||||
for index, (boat, position) in enumerate(self._boats.items(), start=1):
|
for index, (boat, position) in enumerate(self._boats.items(), start=1):
|
||||||
# Paste the boat into the board at the correct position.
|
# Paste the boat into the board at the correct position.
|
||||||
|
@ -116,4 +117,3 @@ if __name__ == "__main__":
|
||||||
print(board.bomb((4, 4)))
|
print(board.bomb((4, 4)))
|
||||||
print(board)
|
print(board)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from src.enum import Orientation
|
from source.enums import Orientation
|
||||||
|
|
||||||
|
|
||||||
class Boat:
|
class Boat:
|
|
@ -1,4 +1,4 @@
|
||||||
from src import Boat
|
from source import Boat
|
||||||
|
|
||||||
|
|
||||||
class InvalidBoatPosition(Exception):
|
class InvalidBoatPosition(Exception):
|
|
@ -4,7 +4,7 @@ import numpy as np
|
||||||
def copy_array_offset(src: np.array, dst: np.array, offset: tuple[int, int]) -> None:
|
def copy_array_offset(src: np.array, dst: np.array, offset: tuple[int, int]) -> None:
|
||||||
"""
|
"""
|
||||||
Copy a numpy array into another one with an offset
|
Copy a numpy array into another one with an offset
|
||||||
:src: source array
|
:source: source array
|
||||||
:dst: destination array
|
:dst: destination array
|
||||||
:offset: the offset where to copy the array
|
:offset: the offset where to copy the array
|
||||||
"""
|
"""
|
Loading…
Reference in a new issue