forked from niklasf/python-chess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.py
executable file
·122 lines (96 loc) · 2.61 KB
/
benchmark.py
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
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of the python-chess library.
# Copyright (C) 2012-2015 Niklas Fiekas <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import chess
import timeit
def play_immortal_game():
board = chess.Board()
# 1.e4 e5
board.push_san("e4")
board.push_san("e5")
# 2.f4 exf4
board.push_san("f4")
board.push_san("exf4")
# 3.Bc4 Qh4+
board.push_san("Bc4")
board.push_san("Qh4+")
# 4.Kf1 b5?!
board.push_san("Kf1")
board.push_san("b5")
# 5.Bxb5 Nf6
board.push_san("Bxb5")
board.push_san("Nf6")
# 6.Nf3 Qh6
board.push_san("Nf3")
board.push_san("Qh6")
# 7.d3 Nh5
board.push_san("d3")
board.push_san("Nh5")
# 8.Nh4 Qg5
board.push_san("Nh4")
board.push_san("Qg5")
# 9.Nf5 c6
board.push_san("Nf5")
board.push_san("c6")
# 10.g4 Nf6
board.push_san("g4")
board.push_san("Nf6")
# 11.Rg1! cxb5?
board.push_san("Rg1")
board.push_san("cxb5")
# 12.h4! Qg6
board.push_san("h4")
board.push_san("Qg6")
# 13.h5 Qg5
board.push_san("h5")
board.push_san("Qg5")
# 14.Qf3 Ng8
board.push_san("Qf3")
board.push_san("Ng8")
# 15.Bxf4 Qf6
board.push_san("Bxf4")
board.push_san("Qf6")
# 16.Nc3 Bc5
board.push_san("Nc3")
board.push_san("Bc5")
# 17.Nd5 Qxb2
board.push_san("Nd5")
board.push_san("Qxb2")
# 18.Bd6! Bxg1?
board.push_san("Bd6")
board.push_san("Bxg1")
# 19.e5! Qxa1+
board.push_san("e5")
board.push_san("Qxa1+")
# 20.Ke2 Na6
board.push_san("Ke2")
board.push_san("Na6")
# 21.Nxg7+ Kd8
board.push_san("Nxg7+")
board.push_san("Kd8")
# 22.Qf6+! Nxf6
board.push_san("Qf6+")
board.push_san("Nxf6")
# 23.Be7# 1-0
board.push_san("Be7#")
assert board.is_checkmate()
if __name__ == "__main__":
print(timeit.timeit(
stmt="play_immortal_game()",
setup="from __main__ import play_immortal_game",
number=100))