Paweł Łaba
commited on
Commit
·
18385f6
1
Parent(s):
10cb4dc
zmiana w uruchamianiu proagramu
Browse files- app.py +6 -1
- public/index.html +1 -1
- public/script.js +7 -3
app.py
CHANGED
@@ -4,6 +4,7 @@ from fastapi.staticfiles import StaticFiles
|
|
4 |
from starlette.routing import Mount
|
5 |
import numpy as np
|
6 |
from tensorflow import keras
|
|
|
7 |
import json
|
8 |
import os
|
9 |
|
@@ -76,6 +77,10 @@ async def get_status():
|
|
76 |
"model_path": "model/model.keras"
|
77 |
}
|
78 |
|
|
|
|
|
|
|
|
|
79 |
@app.post("/savegame")
|
80 |
async def save_game(request: Request):
|
81 |
try:
|
@@ -90,7 +95,7 @@ async def save_game(request: Request):
|
|
90 |
game_data = {
|
91 |
"final_board": final_board,
|
92 |
"sequence": sequence,
|
93 |
-
"hash":
|
94 |
}
|
95 |
|
96 |
try:
|
|
|
4 |
from starlette.routing import Mount
|
5 |
import numpy as np
|
6 |
from tensorflow import keras
|
7 |
+
import hashlib
|
8 |
import json
|
9 |
import os
|
10 |
|
|
|
77 |
"model_path": "model/model.keras"
|
78 |
}
|
79 |
|
80 |
+
def calculate_board_hash(self, board):
|
81 |
+
"""Calculate a unique hash for the board state"""
|
82 |
+
return hashlib.md5(str(board.tolist()).encode()).hexdigest()
|
83 |
+
|
84 |
@app.post("/savegame")
|
85 |
async def save_game(request: Request):
|
86 |
try:
|
|
|
95 |
game_data = {
|
96 |
"final_board": final_board,
|
97 |
"sequence": sequence,
|
98 |
+
"hash": calculate_board_hash(game_hash)
|
99 |
}
|
100 |
|
101 |
try:
|
public/index.html
CHANGED
@@ -15,6 +15,6 @@
|
|
15 |
</div>
|
16 |
|
17 |
|
18 |
-
<script src="./static/script.js?r=
|
19 |
</body>
|
20 |
</html>
|
|
|
15 |
</div>
|
16 |
|
17 |
|
18 |
+
<script src="./static/script.js?r=4" defer></script>
|
19 |
</body>
|
20 |
</html>
|
public/script.js
CHANGED
@@ -2,6 +2,7 @@ const $ = e =>document.querySelector(e);
|
|
2 |
const board = Array(9).fill(0);
|
3 |
const step = [];
|
4 |
let fitstMove = true;
|
|
|
5 |
const winPatterns = [
|
6 |
[0, 1, 2], [3, 4, 5], [6, 7, 8], // poziome
|
7 |
[0, 3, 6], [1, 4, 7], [2, 5, 8], // pionowe
|
@@ -11,9 +12,11 @@ const winPatterns = [
|
|
11 |
|
12 |
|
13 |
function restart(){
|
14 |
-
board
|
|
|
15 |
step = [];
|
16 |
fitstMove = !fitstMove;
|
|
|
17 |
initializeBoard();
|
18 |
}
|
19 |
|
@@ -67,14 +70,15 @@ function updateBoardDisplay() {
|
|
67 |
if(board[i]!=0)
|
68 |
value = board[i]==1?-1:1;
|
69 |
newBoard.push(value);
|
70 |
-
|
|
|
71 |
method: 'POST',
|
72 |
headers: {
|
73 |
'Content-Type': 'application/json'
|
74 |
},
|
75 |
body: JSON.stringify({ final_board: newBoard, sequence:step })
|
76 |
}).then(res => res.json());
|
77 |
-
|
78 |
|
79 |
} else if (!board.includes(0)) {
|
80 |
messageElement.textContent = 'Remis!';
|
|
|
2 |
const board = Array(9).fill(0);
|
3 |
const step = [];
|
4 |
let fitstMove = true;
|
5 |
+
|
6 |
const winPatterns = [
|
7 |
[0, 1, 2], [3, 4, 5], [6, 7, 8], // poziome
|
8 |
[0, 3, 6], [1, 4, 7], [2, 5, 8], // pionowe
|
|
|
12 |
|
13 |
|
14 |
function restart(){
|
15 |
+
board.clear();
|
16 |
+
board.push(...Array(9).fill(0));
|
17 |
step = [];
|
18 |
fitstMove = !fitstMove;
|
19 |
+
|
20 |
initializeBoard();
|
21 |
}
|
22 |
|
|
|
70 |
if(board[i]!=0)
|
71 |
value = board[i]==1?-1:1;
|
72 |
newBoard.push(value);
|
73 |
+
}
|
74 |
+
fetch('/savegame', {
|
75 |
method: 'POST',
|
76 |
headers: {
|
77 |
'Content-Type': 'application/json'
|
78 |
},
|
79 |
body: JSON.stringify({ final_board: newBoard, sequence:step })
|
80 |
}).then(res => res.json());
|
81 |
+
|
82 |
|
83 |
} else if (!board.includes(0)) {
|
84 |
messageElement.textContent = 'Remis!';
|