diff --git a/NOTE.md b/NOTE.md
index 17686b1..4b9dff0 100644
--- a/NOTE.md
+++ b/NOTE.md
@@ -3,14 +3,14 @@ A faire :
1. Principal :
- Documenter (Docstring, README, ...)
- - test avec "assert" (cahier des charges)
- mode d'emploi (video + pdf) expliquant le fonctionnement
2. Bonus :
- sauvegarder les paramètres dans un fichier
3. Bug :
- - /
+ - Impossible de changer le volume sur linux
+ - Cliquer trop vite coupe le son
4. Vérification :
- Tester sur Linux
diff --git a/assets/image/result/.kdenlive/background.png b/assets/image/result/.kdenlive/background.png
new file mode 100644
index 0000000..f667530
Binary files /dev/null and b/assets/image/result/.kdenlive/background.png differ
diff --git a/assets/image/result/.kdenlive/chevron.png b/assets/image/result/.kdenlive/chevron.png
new file mode 100644
index 0000000..75fcc9c
Binary files /dev/null and b/assets/image/result/.kdenlive/chevron.png differ
diff --git a/assets/image/result/.kdenlive/defeat.kdenlive b/assets/image/result/.kdenlive/defeat.kdenlive
new file mode 100644
index 0000000..9cda4cb
--- /dev/null
+++ b/assets/image/result/.kdenlive/defeat.kdenlive
@@ -0,0 +1,410 @@
+
+
+
+
+ 125
+ pause
+
+ 1
+ 1
+ 1
+ kdenlivetitle
+ 125
+ Victoire
+ <kdenlivetitle duration="125" LC_NUMERIC="C" width="1920" height="1080" out="124">
+ <item type="QGraphicsTextItem" z-index="0">
+ <position x="598" y="434">
+ <transform>1,0,0,0,1,0,0,0,1</transform>
+ </position>
+ <content line-spacing="0" shadow="1;#64000000;10;5;6" font-underline="0" box-height="245" font-outline-color="0,0,0,255" font="Century Gothic" letter-spacing="0" font-pixel-size="200" font-italic="0" typewriter="0;1;1;0;0" alignment="4" font-weight="75" font-outline="3" box-width="729" font-color="255,255,255,255">Défaite</content>
+ </item>
+ <startviewport rect="0,0,1920,1080"/>
+ <endviewport rect="0,0,1920,1080"/>
+ <background color="0,0,0,0"/>
+</kdenlivetitle>
+
+ -1
+ 2
+ 3
+ 5352d10ffc6fee2ef8bfc95db4eceedb
+ 0
+ 1920
+ 1080
+
+
+ 00:00:05.000
+ pause
+ background.png
+ 25
+ 1
+ 1
+ 1
+ 2
+ 1920
+ 1080
+ qimage
+
+ 00:00:05.000
+ -1
+ 2
+ 4
+ 10670
+ 7fbb59f3d68679fdd9322cd9f675b781
+
+
+ 00:00:05.000
+ pause
+ chevron.png
+ 25
+ 1
+ 1
+ 1
+ 2
+ 372
+ 201
+ qimage
+
+ 00:00:05.000
+ -
+ chevron.png
+ 2
+ 2
+ 6589
+ f85f1e5d5d8771dd5ae13a4f300a3160
+ -1
+
+
+ 3
+ 2
+ -1
+ 1
+ 0-75
+ 0
+ 1678437287130
+ 1
+ 0
+ 0
+
+ 0
+ 0
+ [
+]
+
+ [
+ {
+ "color": "#000000",
+ "comment": "Catégorie 1 ",
+ "index": 0
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 2 ",
+ "index": 1
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 3 ",
+ "index": 2
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 4 ",
+ "index": 3
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 5 ",
+ "index": 4
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 6 ",
+ "index": 5
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 7 ",
+ "index": 6
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 8 ",
+ "index": 7
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 9 ",
+ "index": 8
+ }
+]
+
+ 22.12.0
+ 62
+
+ mkv
+ vcodec=h264_nvenc g=1 bf=0 preset=fast qmin=10 qmax=30
+ atsc_1080p_25
+
+ 2000
+ 800
+ 1000
+
+ 640
+ Video with Alpha
+ 25
+ -1
+ 0
+ 0
+ 0
+ 0
+ Alpha VP9
+ 1
+ 0
+ 540
+ 960
+ 1
+ -1
+ 0
+ -1
+ 0
+ defeat.webm
+ 0
+ 30000
+ 1.04
+ 1
+ 0
+ 0
+ 105
+ 4
+
+
+ 1
+
+
+
+
+
+ 2147483647
+ continue
+ black
+ 1
+ color
+ rgba
+ 0
+
+
+
+ 4
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=-960 -540 3840 2160 0.000000;00:00:00.760=-960 -540 3840 2160 0.350000;00:00:03.000=-960 -540 3840 2160 0.350000;00:00:04.160=-960 -540 3840 2160 0.000000
+ 00:00:00.000=0;00:00:00.760=0;00:00:03.000=0;00:00:04.160=0
+ 0
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+
+
+
+
+
+ 2
+ 0
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=672 -300 576 324 1.000000;00:00:00.280=672 600 576 324 1.000000;00:00:02.000=672 600 576 324 1.000000;00:00:02.240=672 1540 576 324 1.000000
+ 00:00:00.000=0;00:00:00.280=0;00:00:02.000=0;00:00:02.240=0
+ 0
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+ 2
+ 0
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=672 -820 576 324 1.000000;00:00:00.280=672 380 576 324 1.000000;00:00:01.960=672 380 576 324 1.000000;00:00:02.200=672 1320 576 324 1.000000
+ 00:00:00.000=0;00:00:00.280=0;00:00:01.960=0;00:00:02.200=0
+ 0
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+ 2
+ 0
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=672 -1040 576 324 1.000000;00:00:00.280=672 160 576 324 1.000000;00:00:01.920=672 160 576 324 1.000000;00:00:02.160=672 1100 576 323 1.000000
+ 00:00:00.000=0;00:00:00.280=0;00:00:01.920=0;00:00:02.160=0
+ 0
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+ 3
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=950 535 19 10 1.000000;00:00:00.200=-480 -270 2880 1620 1.000000
+ 00:00:00.000=0;00:00:00.200=0
+ 0
+ 0
+ 0
+
+
+ 1
+ 1
+ brightness
+ fade_to_black
+ 00:00:00.000=1;00:00:01.000=0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+ 0
+ 0
+ 0
+ qtblend
+ qtblend
+ 237
+ 1
+
+
+ 0
+ 2
+ 0
+ 0
+ 0
+ qtblend
+ qtblend
+ 237
+ 1
+
+
+ 0
+ 3
+ 0
+ 0
+ 0
+ qtblend
+ qtblend
+ 237
+ 1
+
+
+ 0
+ 4
+ 0
+ 0
+ 0
+ qtblend
+ qtblend
+ 237
+ 1
+
+
+ 0
+ 5
+ 0
+ 0
+ 0
+ qtblend
+ qtblend
+ 237
+ 1
+
+
+ 75
+ 20dB
+ volume
+ 237
+ 1
+
+
+ -1
+ panner
+ 237
+ 0.5
+ 1
+
+
+
diff --git a/assets/image/result/.kdenlive/line.png b/assets/image/result/.kdenlive/line.png
new file mode 100644
index 0000000..1c088c2
Binary files /dev/null and b/assets/image/result/.kdenlive/line.png differ
diff --git a/assets/image/result/.kdenlive/victory.kdenlive b/assets/image/result/.kdenlive/victory.kdenlive
new file mode 100644
index 0000000..b227cc3
--- /dev/null
+++ b/assets/image/result/.kdenlive/victory.kdenlive
@@ -0,0 +1,453 @@
+
+
+
+
+ 00:00:05.000
+ pause
+ line.png
+ 25
+ 1
+ 1
+ 1
+ 2
+ 328
+ 1080
+ qimage
+
+ 00:00:05.000
+ -1
+ 2
+ 2
+ 13558
+ 3a4f54a7b392eb93d62359265573c322
+
+
+ 125
+ pause
+
+ 1
+ 1
+ 1
+ kdenlivetitle
+ 125
+ Victoire
+ <kdenlivetitle duration="125" LC_NUMERIC="C" width="1920" height="1080" out="124">
+ <item type="QGraphicsTextItem" z-index="0">
+ <position x="587" y="434">
+ <transform>1,0,0,0,1,0,0,0,1</transform>
+ </position>
+ <content line-spacing="0" shadow="1;#64000000;10;5;6" font-underline="0" box-height="245" font-outline-color="0,0,0,255" font="Century Gothic" letter-spacing="0" font-pixel-size="200" font-italic="0" typewriter="0;1;1;0;0" alignment="4" font-weight="75" font-outline="3" box-width="747" font-color="255,255,255,255">Victoire</content>
+ </item>
+ <startviewport rect="0,0,1920,1080"/>
+ <endviewport rect="0,0,1920,1080"/>
+ <background color="0,0,0,0"/>
+</kdenlivetitle>
+
+ -1
+ 2
+ 3
+ 5352d10ffc6fee2ef8bfc95db4eceedb
+ 0
+ 1920
+ 1080
+
+
+ 00:00:05.000
+ pause
+ background.png
+ 25
+ 1
+ 1
+ 1
+ 2
+ 1920
+ 1080
+ qimage
+
+ 00:00:05.000
+ -1
+ 2
+ 4
+ 10670
+ 7fbb59f3d68679fdd9322cd9f675b781
+
+
+ 3
+ 2
+ -1
+ 1
+ 0-75
+ 0
+ 1678437287130
+ 1
+ 0
+ 0
+
+ 0
+ 0
+ [
+ {
+ "children": [
+ {
+ "data": "3:10",
+ "leaf": "clip",
+ "type": "Leaf"
+ },
+ {
+ "data": "2:5",
+ "leaf": "clip",
+ "type": "Leaf"
+ },
+ {
+ "data": "1:0",
+ "leaf": "clip",
+ "type": "Leaf"
+ }
+ ],
+ "type": "Normal"
+ }
+]
+
+ [
+ {
+ "color": "#000000",
+ "comment": "Catégorie 1 ",
+ "index": 0
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 2 ",
+ "index": 1
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 3 ",
+ "index": 2
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 4 ",
+ "index": 3
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 5 ",
+ "index": 4
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 6 ",
+ "index": 5
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 7 ",
+ "index": 6
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 8 ",
+ "index": 7
+ },
+ {
+ "color": "#000000",
+ "comment": "Catégorie 9 ",
+ "index": 8
+ }
+]
+
+ 22.12.0
+ 0
+
+ mkv
+ vcodec=h264_nvenc g=1 bf=0 preset=fast qmin=10 qmax=30
+ atsc_1080p_25
+
+ 2000
+ 800
+ 1000
+
+ 640
+ Video with Alpha
+ 25
+ -1
+ 0
+ 0
+ 0
+ 0
+ Alpha VP9
+ 1
+ 0
+ 540
+ 960
+ 1
+ -1
+ 0
+ -1
+ 0
+ C:/Users/RC606/Videos/victory.webm
+ 0
+ 30000
+ 1.04
+ 1
+ -1
+ 0
+ 105
+ 4
+
+
+ 1
+
+
+
+
+
+ 2147483647
+ continue
+ black
+ 1
+ color
+ rgba
+ 0
+
+
+
+ 4
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=-960 -540 3840 2160 0.000000;00:00:00.760=-960 -540 3840 2160 0.350000;00:00:03.000=-960 -540 3840 2160 0.350000;00:00:04.160=-960 -540 3840 2160 0.000000
+ 00:00:00.000=0;00:00:00.760=0;00:00:03.000=0;00:00:04.160=0
+ 0
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+ 2
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=1200 0 1920 1080 1.000000;00:00:00.280=-250 0 1920 1080 1.000000;00:00:00.840=-250 0 1920 1080 1.000000;00:00:01.000=-4600 -2160 9600 5400 1.000000;00:00:02.000=-4600 -2160 9600 5400 1.000000;00:00:02.280=-6680 -2157 9600 5400 1.000000
+ 00:00:00.000=0;00:00:00.280=0;00:00:00.840=0;00:00:01.000=0;00:00:02.000=0;00:00:02.280=0
+ 0
+ 0
+ 0
+
+
+ 0.9
+ frei0r.softglow
+ frei0r.softglow
+ 00:00:00.000=0;00:00:00.840=0;00:00:01.000=0.654891
+ 00:00:00.000=0;00:00:00.840=0;00:00:01.000=1
+ 00:00:00.000=0;00:00:00.840=0;00:00:01.000=1
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+ 2
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=1450 0 1920 1080 1.000000;00:00:00.400=0 0 1920 1080 1.000000;00:00:00.640=0 0 1920 1080 1.000000;00:00:00.800=-3840 -2160 9600 5400 1.000000;00:00:02.080=-3840 -2160 9600 5400 1.000000;00:00:02.360=-5940 -2160 9600 5400 1.000000
+ 00:00:00.000=0;00:00:00.400=0;00:00:00.640=0;00:00:00.800=0;00:00:02.080=0;00:00:02.360=0
+ 0
+ 0
+ 0
+
+
+ 0.9
+ frei0r.softglow
+ frei0r.softglow
+ 00:00:00.000=0;00:00:00.640=0;00:00:00.800=0.65
+ 00:00:00.000=0;00:00:00.640=0;00:00:00.800=1
+ 00:00:00.000=0;00:00:00.640=0;00:00:00.800=1
+ 0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+ 2
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=1600 0 1920 1080 1.000000;00:00:00.400=250 0 1920 1080 1.000000;00:00:00.440=250 0 1920 1080 1.000000;00:00:00.600=-3100 -2160 9600 5400 1.000000;00:00:02.160=-3100 -2160 9600 5400 1.000000;00:00:02.440=-5200 -2160 9600 5400 0.984127
+ 00:00:00.000=0;00:00:00.400=0;00:00:00.440=0;00:00:00.600=0;00:00:02.160=0;00:00:02.440=0
+ 0
+ 0
+ 0
+
+
+ 0.9
+ frei0r.softglow
+ frei0r.softglow
+ 00:00:00.000=0;00:00:00.440=0;00:00:00.600=0.651748
+ 00:00:00.000=0;00:00:00.440=0;00:00:00.600=1
+ 00:00:00.000=0;00:00:00.440=0;00:00:00.600=1
+ 0
+ 1
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+ 3
+
+ 1
+ qtblend
+ qtblend
+ 00:00:00.000=950 535 19 10 1.000000;00:00:00.200=-480 -270 2880 1620 1.000000
+ 00:00:00.000=0;00:00:00.200=0
+ 0
+ 0
+ 0
+
+
+ 1
+ 1
+ brightness
+ fade_to_black
+ 00:00:00.000=1;00:00:01.000=0
+ 0
+
+
+
+
+
+ 67
+ 1
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+ 0
+ 0
+ 0
+ qtblend
+ 1
+ 237
+
+
+ 0
+ 2
+ 0
+ 0
+ 0
+ qtblend
+ 1
+ 237
+
+
+ 0
+ 3
+ 0
+ 0
+ 0
+ qtblend
+ 1
+ 237
+
+
+ 0
+ 4
+ 0
+ 0
+ 0
+ qtblend
+ 1
+ 237
+
+
+ 0
+ 5
+ 0
+ 0
+ 0
+ qtblend
+ 1
+ 237
+
+
+ 75
+ 20dB
+ volume
+ 237
+ 1
+
+
+ -1
+ panner
+ 237
+ 0.5
+ 1
+
+
+
diff --git a/source/_test/core.py b/source/_test/core.py
index 6b41e66..b8e742e 100644
--- a/source/_test/core.py
+++ b/source/_test/core.py
@@ -1,11 +1,79 @@
import unittest
+import numpy as np
+
+from source.core import Board, Boat
+from source.core.enums import Orientation, BombState
+from source.core.error import InvalidBoatPosition, InvalidBombPosition, PositionAlreadyShot
+
class TestCore(unittest.TestCase):
- # TODO
- def test_something(self):
- self.assertEqual(True, False) # add assertion here
+ def test_boats(self):
+ board = Board(width=5, height=5)
+ board.add_boat(Boat(5, Orientation.HORIZONTAL), (0, 0))
+
+ self.assertTrue((board.boats == np.array([
+ [1, 1, 1, 1, 1],
+ [0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0],
+ ])).all())
+
+ board.add_boat(Boat(4, Orientation.VERTICAL), (1, 1))
+
+ self.assertTrue((board.boats == np.array([
+ [1, 1, 1, 1, 1],
+ [0, 2, 0, 0, 0],
+ [0, 2, 0, 0, 0],
+ [0, 2, 0, 0, 0],
+ [0, 2, 0, 0, 0],
+ ])).all())
+
+ self.assertRaises(
+ InvalidBoatPosition,
+ board.add_boat,
+ Boat(3, Orientation.HORIZONTAL),
+ (1, 1)
+ )
+
+ self.assertRaises(
+ InvalidBoatPosition,
+ board.add_boat,
+ Boat(3, Orientation.HORIZONTAL),
+ (4, 1)
+ )
+
+ def test_bombs(self):
+ board = Board(width=5, height=5)
+ board.add_boat(Boat(5, Orientation.HORIZONTAL), (0, 0))
+ board.add_boat(Boat(4, Orientation.VERTICAL), (1, 1))
+
+ self.assertEqual(board.bomb((0, 0)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((1, 0)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((2, 0)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((3, 0)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((4, 0)), BombState.SUNKEN)
+
+ self.assertEqual(board.bomb((0, 1)), BombState.NOTHING)
+
+ self.assertRaises(
+ InvalidBombPosition,
+ board.bomb,
+ (10, 10)
+ )
+
+ self.assertRaises(
+ PositionAlreadyShot,
+ board.bomb,
+ (0, 0)
+ )
+
+ self.assertEqual(board.bomb((1, 1)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((1, 2)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((1, 3)), BombState.TOUCHED)
+ self.assertEqual(board.bomb((1, 4)), BombState.WON)
if __name__ == '__main__':
diff --git a/source/_test/network.py b/source/_test/network.py
index a04ee5a..05d9304 100644
--- a/source/_test/network.py
+++ b/source/_test/network.py
@@ -5,11 +5,17 @@ import random
from threading import Thread
from typing import Optional
-from source.network.packet import PacketChat
+import numpy as np
+
+from source.core.enums import BombState
+from source.network.packet import PacketChat, PacketUsername, PacketQuit, PacketAskSave, PacketBoatPlaced, \
+ PacketLoadOldSave, PacketResponseSave, PacketHaveSaveBeenFound, PacketBombPlaced, PacketBombState, PacketSettings, \
+ PacketBoatsData
+from source.network.packet.abc import Packet
class TestNetwork(unittest.TestCase):
- PORT: int = 54231
+ PORT: int = 54200
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -36,17 +42,140 @@ class TestNetwork(unittest.TestCase):
self.co_client.close()
self.so_server.close()
- def test_packet_chat(self):
+ # tous les tests de packet sont réunis dans la même fonction pour éviter de réouvrir des sockets sur le mêmes
+ # ports encore et encore
+ def test_packet(self):
+ # PacketChat
for _ in range(100):
- message = "".join(random.choice(string.printable) for _ in range(random.randint(1, 100)))
+ packet_sent = PacketChat(
+ message="".join(random.choice(string.printable) for _ in range(random.randint(1, 100)))
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketChat.from_connection(self.co_client)
- PacketChat(message).send_data_connection(self.co_server)
- packet_chat = PacketChat.from_connection(self.co_client)
+ self.assertEqual(packet_sent, packet_recv)
- self.assertEqual(message, packet_chat.message)
+ # PacketUsername
+ for _ in range(100):
+ packet_sent = PacketUsername(
+ username="".join(random.choice(string.printable) for _ in range(random.randint(1, 16)))
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketUsername.from_connection(self.co_client)
- # TODO: autre type de packets
- # TODO: type de packet générique
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketQuit
+ for _ in range(100):
+ PacketQuit().send_data_connection(self.co_server)
+ PacketQuit.from_connection(self.co_client)
+
+ # PacketAskSave
+ for _ in range(100):
+ PacketAskSave().send_data_connection(self.co_server)
+ PacketAskSave.from_connection(self.co_client)
+
+ # PacketBoatPlaced
+ for _ in range(100):
+ PacketBoatPlaced().send_data_connection(self.co_server)
+ PacketBoatPlaced.from_connection(self.co_client)
+
+ # PacketLoadOldSave
+ for _ in range(100):
+ packet_sent = PacketLoadOldSave(
+ value=bool(random.randint(0, 1))
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketLoadOldSave.from_connection(self.co_client)
+
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketResponseSave
+ for _ in range(100):
+ packet_sent = PacketResponseSave(
+ value=bool(random.randint(0, 1))
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketResponseSave.from_connection(self.co_client)
+
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketHaveSaveBeenFound
+ for _ in range(100):
+ packet_sent = PacketHaveSaveBeenFound(
+ value=bool(random.randint(0, 1))
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketHaveSaveBeenFound.from_connection(self.co_client)
+
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketBombPlaced
+ for _ in range(100):
+ packet_sent = PacketBombPlaced(
+ (random.randint(0, 64), random.randint(0, 64))
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketBombPlaced.from_connection(self.co_client)
+
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketBombState
+ for _ in range(100):
+ packet_sent = PacketBombState(
+ position=(random.randint(0, 64), random.randint(0, 64)),
+ bomb_state=random.choice(list(BombState)),
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketBombState.from_connection(self.co_client)
+
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketSettings
+ for _ in range(100):
+ packet_sent = PacketSettings(
+ grid_width=random.randint(0, 64),
+ grid_height=random.randint(0, 64),
+ host_start=bool(random.randint(0, 1)),
+ boats_length=[random.randint(1, 16) for _ in range(random.randint(1, 32))]
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketSettings.from_connection(self.co_client)
+
+ self.assertEqual(packet_sent, packet_recv)
+
+ # PacketBoatsData
+ for _ in range(100):
+ packet_sent = PacketBoatsData(
+ boats=(
+ np.random.rand(
+ random.randint(2, 32),
+ random.randint(2, 32),
+ ) * random.randint(1, 65535)
+ ).astype(dtype=np.ushort)
+ )
+ packet_sent.send_data_connection(self.co_server)
+ packet_recv = PacketBoatsData.from_connection(self.co_client)
+
+ self.assertTrue((packet_sent.boats == packet_recv.boats).all()) # NOQA
+
+ # Packet Générique
+ for _ in range(100):
+ # prend un packet signal aléatoire (sont plus simples a initialisé)
+ packet_sent_type = random.choice([PacketQuit, PacketAskSave, PacketBoatPlaced, PacketUsername, PacketChat])
+
+ if packet_sent_type in [PacketUsername, PacketChat]:
+ packet_sent = packet_sent_type(
+ "".join(random.choice(string.printable) for _ in range(random.randint(1, 16)))
+ )
+ else:
+ packet_sent = packet_sent_type()
+
+ packet_sent.send_connection(self.co_server)
+ packet_recv_type = Packet.type_from_connection(self.co_client)
+ packet_recv = packet_recv_type.from_connection(self.co_client)
+
+ self.assertEqual(packet_recv, packet_sent)
if __name__ == '__main__':
diff --git a/source/core/Board.py b/source/core/Board.py
index a2ac2f1..9129df0 100644
--- a/source/core/Board.py
+++ b/source/core/Board.py
@@ -162,16 +162,3 @@ class Board:
boats=self.boats.copy(),
bombs=self.bombs.copy(),
)
-
-
-if __name__ == "__main__":
- board = Board(5, 10)
- board.add_boat(Boat(3, Orientation.VERTICAL), (4, 0))
- board.add_boat(Boat(4, Orientation.HORIZONTAL), (1, 4))
- print(board.bomb((4, 1)))
- print(board.bomb((4, 2)))
- print(board.bomb((4, 3)))
- print(board.bomb((4, 4)))
- print(board)
-
- print(board.to_json())
diff --git a/source/network/packet/PacketAskSave.py b/source/network/packet/PacketAskSave.py
index 915b919..75b80d3 100644
--- a/source/network/packet/PacketAskSave.py
+++ b/source/network/packet/PacketAskSave.py
@@ -1,6 +1,9 @@
+from dataclasses import dataclass
+
from source.network.packet.abc import SignalPacket
+@dataclass
class PacketAskSave(SignalPacket):
"""
A packet that is sent when the player wish to save the game.
diff --git a/source/network/packet/PacketBoatPlaced.py b/source/network/packet/PacketBoatPlaced.py
index 3d66813..ec740fa 100644
--- a/source/network/packet/PacketBoatPlaced.py
+++ b/source/network/packet/PacketBoatPlaced.py
@@ -1,6 +1,9 @@
+from dataclasses import dataclass
+
from source.network.packet.abc import SignalPacket
+@dataclass
class PacketBoatPlaced(SignalPacket):
"""
A packet that signal that all the boat of the player have been placed
diff --git a/source/network/packet/PacketBoatsData.py b/source/network/packet/PacketBoatsData.py
index a515282..439a15b 100644
--- a/source/network/packet/PacketBoatsData.py
+++ b/source/network/packet/PacketBoatsData.py
@@ -10,7 +10,7 @@ from source.network.packet.abc import Packet
@dataclass
class PacketBoatsData(Packet):
- boats: np.ndarray = field()
+ boats: np.array = field()
packet_format: str = ">II"
diff --git a/source/network/packet/PacketQuit.py b/source/network/packet/PacketQuit.py
index 462be95..479906d 100644
--- a/source/network/packet/PacketQuit.py
+++ b/source/network/packet/PacketQuit.py
@@ -1,6 +1,9 @@
+from dataclasses import dataclass
+
from source.network.packet.abc import SignalPacket
+@dataclass
class PacketQuit(SignalPacket):
"""
A packet that is sent when the player wish to quit a game.