-
Notifications
You must be signed in to change notification settings - Fork 1
/
board-creator.php
72 lines (64 loc) · 2.02 KB
/
board-creator.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
function createBoard ( $p = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR', $s = 'w', $lastmove = '', $board = 'blue2') {
header("Content-type: image/png");
$board = imagecreatefrompng("images/boards/$board.png");
$move = imagecreatefrompng("images/last.png");
$pieces = array(
'K' => imagecreatefrompng("images/wk.png"),
'Q' => imagecreatefrompng("images/wq.png"),
'R' => imagecreatefrompng("images/wr.png"),
'B' => imagecreatefrompng("images/wb.png"),
'N' => imagecreatefrompng("images/wn.png"),
'P' => imagecreatefrompng("images/wp.png"),
'k' => imagecreatefrompng("images/k.png"),
'q' => imagecreatefrompng("images/q.png"),
'r' => imagecreatefrompng("images/r.png"),
'b' => imagecreatefrompng("images/b.png"),
'n' => imagecreatefrompng("images/n.png"),
'p' => imagecreatefrompng("images/p.png")
);
$a_to_n = array(
'a' => 0,
'b' => 1,
'c' => 2,
'd' => 3,
'e' => 4,
'f' => 5,
'g' => 6,
'h' => 7
);
if ( strlen( $lastmove ) == 4 ) {
$lastmove = str_split( $lastmove );
if ( $s == 'w' ) {
imagecopy( $board, $move, 50*($a_to_n[$lastmove[0]]), 50*(8-$lastmove[1]), 0, 0, 50, 50 );
imagecopy( $board, $move, 50*($a_to_n[$lastmove[2]]), 50*(8-$lastmove[3]), 0, 0, 50, 50 );
} else {
imagecopy( $board, $move, 50*(7-$a_to_n[$lastmove[0]]), 50*($lastmove[1]-1), 0, 0, 50, 50 );
imagecopy( $board, $move, 50*(7-$a_to_n[$lastmove[2]]), 50*($lastmove[3]-1), 0, 0, 50, 50 );
}
}
$position = explode('/', $p);
if ( $s == 'b' ) {
foreach ( $position as $key => $rank ) {
$position[7-$key] = array_reverse( str_split ($rank) );
}
} else {
foreach ( $position as $key => $rank ) {
$position[$key] = str_split ($rank);
}
}
foreach ( $position as $number => $rank ) {
$row = 0;
foreach ( $rank as $square ) {
if ( intval( $square ) > 0 ) {
$row += intval( $square );
} else {
imagecopy( $board, $pieces[$square], 50*$row, 50*$number, 0, 0, 50, 50 );
$row++;
}
}
}
imagepng($board);
imagedestroy($board);
}
createBoard($argv[1], $argv[2], $argv[3]);