makefile
[arrocco.git] / arrocco.py
blob6f30b34abc4b0f6a622f5891fe8064c9f13e780a
1 #!/usr/bin/env python2.5
2 # arrocco.py
3 # main file
5 """
6 This file is part of Arrocco, which is Copyright 2007 Thomas Plick
7 (tomplick 'at' gmail.com).
9 Arrocco is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 Arrocco is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 """
23 import getopt, sys, cpu
24 from position import *
25 from search import *
26 from partest import *
28 def intlog(x):
29 n = 0
30 while x > 1:
31 x = int(x/2)
32 n += 1
33 return n
35 options, args = getopt.getopt(sys.argv[1:], "a24", ["cpus="])
36 options = dict(options)
38 fen = (args + [ipos.fen()])[0]
39 pos = position(fen)
41 measuredCpus = cpu.count_cpus()
43 cpus = 1
44 if '-a' in options: cpus = measuredCpus
45 elif '-2' in options: cpus = 2
46 elif '-4' in options: cpus = 4
47 else:
48 try:
49 cpus = int(options['--cpus'])
50 except:
51 cpus = 1
53 splits = intlog(cpus)
54 print "Using %s CPUs." % (2**splits)
55 if measuredCpus > cpus:
56 print " (Note: You specified %s CPU%s, but your system appears to have %s." % \
57 (cpus, '' if cpus == 1 else 's', measuredCpus)
58 print " If you would like to use them, specify `--cpus=%s' on the command line.)" % \
59 (measuredCpus)
61 def mainidea():
62 print pos
63 for d in range(3, 100):
64 x = alphaBeta(pos, d, top = True, splits = splits)
65 print "\nDepth %d:" % d
66 print " ", removePV(x)
67 print " ", algebraicForPV(x['pv'])
69 if __name__ == '__main__':
70 thread.start_new_thread(mainidea, ())
71 while 1:
72 time.sleep(1000)