-
Notifications
You must be signed in to change notification settings - Fork 62
/
play.php
37 lines (30 loc) · 1.22 KB
/
play.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
session_start();
include_once 'util.php';
$piece = $_POST['piece'];
$to = $_POST['to'];
$player = $_SESSION['player'];
$board = $_SESSION['board'];
$hand = $_SESSION['hand'][$player];
if (!$hand[$piece])
$_SESSION['error'] = "Player does not have tile";
elseif (isset($board[$to]))
$_SESSION['error'] = 'Board position is not empty';
elseif (count($board) && !hasNeighBour($to, $board))
$_SESSION['error'] = "board position has no neighbour";
elseif (array_sum($hand) < 11 && !neighboursAreSameColor($player, $to, $board))
$_SESSION['error'] = "Board position has opposing neighbour";
elseif (array_sum($hand) <= 8 && $hand['Q']) {
$_SESSION['error'] = 'Must play queen bee';
} else {
$_SESSION['board'][$to] = [[$_SESSION['player'], $piece]];
$_SESSION['hand'][$player][$piece]--;
$_SESSION['player'] = 1 - $_SESSION['player'];
$db = include 'database.php';
$stmt = $db->prepare('insert into moves (game_id, type, move_from, move_to, previous_id, state) values (?, "play", ?, ?, ?, ?)');
$stmt->bind_param('issis', $_SESSION['game_id'], $piece, $to, $_SESSION['last_move'], get_state());
$stmt->execute();
$_SESSION['last_move'] = $db->insert_id;
}
header('Location: index.php');
?>