online multiplayer chess game (note server currently down)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
extends Node


class TestSan:
	extends SanParser

	func assert_castle(string: String, s):
		var m = parse(string)
		assert(m.move_kind.type == Move.MoveKind.CASTLE)
		assert(m.move_kind.data == s)
		assert(m.piece == KING)
		assert(m.promotion == 0)
		assert(m.check_type == Move.CHECKTYPES.NONE)
		assert(m.is_capture == false)

	func assert_move(mv: String, start: Vector2, dest: Vector2, piece: int) -> void:
		assert_all(parse(mv), PoolVector2Array([start, dest]), piece, false)

	func assert_capture(mv: String, start: Vector2, dest: Vector2, piece: int) -> void:
		assert_all(parse(mv), PoolVector2Array([start, dest]), piece, true)

	func assert_all(mv: Move, vectors: PoolVector2Array, piece: int, capture: bool, promote = -1) -> void:
		assert(mv.move_kind.type == Move.MoveKind.NORMAL)
		assert([mv.move_kind.data == vectors, mv.piece == piece, mv.is_capture == capture].min())
		if promote != -1:
			assert(mv.promotion == promote)

	func test_algebraic_conversion():
		assert(Utils.from_algebraic(Utils.to_algebraic(Vector2.ZERO)) == Vector2.ZERO)
		assert(Utils.from_algebraic(Utils.to_algebraic(Vector2.ONE)) == Vector2.ONE)
		assert(pos("a", "9") == Utils.from_algebraic("a9"))
		assert(Utils.col_pos("h") == 7)
		assert(Utils.row_pos("1") == 7)

	func test_castle_short():
		assert_castle("O-O", Move.CASTLETYPES.KING_SIDE)

	func test_castle_long():
		assert_castle("O-O-O", Move.CASTLETYPES.QUEEN_SIDE)

	func test_pawn():
		assert_move("e4", UNKNOWN_POS, Vector2(4, 4), PAWN)

	func test_pawn_long():
		assert_move("e2e4", Vector2(4, 6), Vector2(4, 4), PAWN)

	func test_piece():
		assert_move("Qe4", UNKNOWN_POS, Vector2(4, 4), QUEEN)

	func test_piece_file():
		assert_move("Qbe4", Vector2(1, -1), Vector2(4, 4), QUEEN)

	func test_piece_rank():
		assert_move("Q1e4", Vector2(-1, 7), Vector2(4, 4), QUEEN)

	func test_piece_long():
		assert_move("Qb1e4", Vector2(1, 7), Vector2(4, 4), QUEEN)

	func test_pawn_capture():
		assert_capture("exd4", Vector2(4, -1), Vector2(3, 4), PAWN)

	func test_pawn_capture_promotion():
		assert_all(parse("exd8=Q"), PoolVector2Array([Vector2(4, -1), Vector2(3, 0)]), PAWN, true, QUEEN)

	func test_pawn_capture_long():
		assert_capture("e3xd4", Vector2(4, 5), Vector2(3, 4), PAWN)

	func test_piece_capture():
		assert_capture("R1xh3", Vector2(-1, 7), Vector2(7, 5), ROOK)

	func test_piece_capture_file():
		assert_capture("Rexh3", Vector2(4, -1), Vector2(7, 5), ROOK)

	func test_piece_capture_long():
		assert_capture("Re3xh3", Vector2(4, 5), Vector2(7, 5), ROOK)

	func test_pawn_promotion():
		assert_all(parse("d8=Q"), PoolVector2Array([UNKNOWN_POS, Vector2(3, 0)]), PAWN, QUEEN)

	func test_compile():
		var s = Move.new(PAWN, [Vector2(4, -1), Vector2(3, 0)])
		s.promotion = QUEEN
		s.check_type = Move.CHECKTYPES.CHECK
		s.is_capture = true
		var result = s.compile()
		assert(result == "exd8=Q+")
		assert(Move.parse("e4").compile() == "e4")

	func _init():
		test_algebraic_conversion()
		test_castle_short()
		test_castle_long()
		test_pawn()
		test_pawn_long()
		test_piece()
		test_piece_file()
		test_piece_rank()
		test_piece_long()
		test_pawn_capture()
		test_pawn_capture_promotion()
		test_pawn_capture_long()
		test_piece_capture()
		test_piece_capture_file()
		test_piece_capture_long()
		test_pawn_promotion()
		test_compile()


func _ready():
	TestSan.new()