Youtube Channel dedicated to chess programs ( play list starting with Alan Turing - The first ever Chess program )
http://www.youtube.com/watch?v=CrLbB4ie ... NmGb7REmpv
Finally getting round to building a proper chess engine. There are some very strong engines out there but essential elements like LAN play and utilizing the processing power of other CPU's on a network are either buggy, an afterthought or just haven't been implemented.
This is for x86 PC's / PC networks running windows and while FreeBASIC is slower than some other languages and no doubt my code will not be the fastest but the ability to add an infinite number of machines will more than make up for any shortfall. Stringing together a couple of clunkers can turn you computer museum into a chess monster.
The main exe will handle all the misc stuff and brute force to 6 ply and then select various lines for further analysis by other local exe's or remote cpu's depending on the filters set by the user. Simple file sharing is all that required combined with elementary message based computing.
*a hobby coder has no chance of writing a truly competitive engine that runs on a single machine, the ability to utilize other machines at least gives you a fighting chance. Most of us have 2 or 3 desktop machines these days & perhaps a laptop or two. Network cables & routers/switches are cheap and chances are you have most of the kit already. Got CPU's ? why not use em !
Q why am i doing this ?
Well i have 3 projects / ambitions and this is the 3rd. Im investing $1000's in a computer network to host my self aware HAL9000 type AI system. ( destined to be the smartest AI on the planet ) The Epic Space game runs on the older parts of the network as i upgrade it and will eventually bring in some revenue, and its my intention that my network Chess Computer be the most powerful dedicated chess computer in the UK if not the world. Playing chess for big prize money, but you have to get in the top 100 if not top 10 to make a living out of it and that is my intention here and that means writing chess software that can run on a network of any size. There is a great deal of crossover between the three projects and having made a lot of headway in one its easy to branch out.
Chess is entering its last phase. By the end of this century it will be mostly strongly solved so the fun will be over by 2100ad. In the near future we are going to see some titanic battles between supercomputers with millions of cores and i just want to be part of that fun. That and contribute to the knowledge of mankind.
Ive included some links to useful information as writing a proper bug free chess program is a lot more complicated than it appears at first glance. So forgive the link spam.
Tips for writing a chess program
Many very experienced coders come unstuck as chess is full of weird and wonderful exceptions to the rule. Pressures to optimize the code for speed, cope with the numerous chess formats or just get the GUI looking sweet all lend their weight. 99% of all code attempts will be riddled with nasty chess bugs because the coder didn't think of all the exceptions they have to handle in advance.
The most important code element is the legal move generator...thats ALL legal moves and not just the ones that spring to mind thank you very much ! lol
A typical chess program will use several internal data formats and will include quite a large amount of spaghetti fudge code in order to handle all those awkward exceptions to the rule which inevitable arise and cannot be dealt with neatly or efficiently.
Draw by repetition is particularly tricky to handle as you not only have to check for this at every single branch but you have to evaluate it too, and sometimes you have to evaluate it retrospectively because if a deeper search indicates you are 'now losing' or 'now winning' then you will want to actively steer away or towards 'draw by repetition'. Worse still draw by repetition often arrives in batches that suddenly multiply exponentially and may well involve a long series of moves which are not necessarily checks. If a chess program cannot handle this well then it falls firmly into the dud-ware category. Its up there with crashing into clouds :-p
Graphics Chess Set Designs & the International Tournament Standard
http://www.youtube.com/watch?v=nO448CufFJw
Chess programming
Writing a chess program in 99 steps
http://www.sluijten.com/winglet/
http://chessprogramming.wikispaces.com/
http://www.frayn.net/beowulf/theory.html
http://tinyurl.com/bpd29ej
ADDED misc tools
Fritzbench conversion / ELO estimator / CPU architecture comparison
Code: Select all
'Fritzbench conversion / elo estimator / CPU architecture comparison
dim i as ULONGINT
dim mem as integer
dim st as double
dim fin as double
dim mips as double
dim q as integer
dim as integer mpint,cores,fritzb,elo
color 13
?
?" Fritzbench conversion / elo estimator / CPU architecture comparison"
'goto skip
mem = FRE
color 12
?:?" Free memory:" ;mem \ (1024 * 1024); " megabytes"
color 7
?:?" starting Free Basic speedtest9.exe....approx 10 seconds":?:sleep 100
st = TIMER :?" start "; st , timer
for i = 1 to 2500000000:next i
fin = TIMER :?" finish "; fin , timer
?: color 13: ?" time = " ;fin-st;" i = ";i;" how many loops done in total"
i=i/1000000
mips = i/ (fin-st)
?:?" mips = "; mips; " FreeBASIC for next loop instructions X 1 million"
'skip:
'mpint = 425
'* 1.30
'? 3.9*1.30
'sleep
'elo = 0
screen 19
mpint = mips
color 13
?
?" Fritz Benchmark Conversion & Comparison Table including ELO aproximation"
color 12
?
?" Your core speed ="; mpint ;" mips using Speedtest9 test as the CPU mark "
color 7
?
?" Applying your single core speed to different architectures & converting to Fritzbenchmark"
?
?" No hyper threading Fritz bench"
?
fritzb = mpint *6*1*.95
?" Single = "; fritzb
fritzb = mpint *6*2*.925
?" Dual = "; fritzb
fritzb = mpint *6*3*.895
?" Triple = "; fritzb
fritzb = mpint *6*4*.867
?" Quad = "; fritzb
fritzb = mpint *6*6*.790
?" Hex = "; fritzb
fritzb = mpint *6*8*.690
?" Octo = "; fritzb
?
?
?" With hyper threading Fritz bench"
?
fritzb = mpint *6*1*.99*1.65
?" Single = "; fritzb
fritzb = mpint *6*2*.86*1.45
?" Dual = "; fritzb
fritzb = mpint *6*3*.86*1.35
?" Triple = "; fritzb
fritzb = mpint *6*4*.86*1.31
?" Quad = "; fritzb
fritzb = mpint *6*6*.86*1.30
?" Hex = "; fritzb
fritzb = mpint *6*8*.69*.95
?" Octo = "; fritzb
?
?" Notes:"
?" Multi core CPU's suffer performance penalites"
?" Hyper threading cores tend to suffer even more"
?" This means a significant % of perfomance is lost"
?" In general Ghz is king, then cores, then threads"
?
?" Calibrated with CPU's 2007 to 2012ad [spread +/- 10%]"
?" * Indvidual cores turboboost higher when tested in isolation"
?
?" hit Enter to exit"
color 6
locate 8,55:? "Fritz ELO HUMAN"
locate 10,55:? " 1 20 Beginner"
locate 11,55:? " 5 500 Casual player"
locate 12,55:? " 50 1200 Weak Club player"
locate 13,55:? " 500 1900 Strong Club player"
locate 14,55:? " 5000 2500 Grandmaster"
locate 15,55:? "10000 2750 World Champion"
locate 16,55:? "20000 3000 Greatest Human Possible"
locate 18,55:? "Note: Very rough aproximation"
sleep: end
' ?" 500 Mhz Pent III = 68"
' ?" Celeron 2600 = 180"
' ?" Sepmron 2600+ = 305"
' ?" Athalon 2000+ = 330"
' ?" Atom N450 2 core = 235 * task manager cpu usage was showing 50% "
' ?" Atom N450 2 core = 335 * running 2 progs at once cpu usage 100% "
' ?" AMD XII 250 = 375"
' ?" AMD FX-8 8350 = 400 * estimated"
' ?" i5 2500k stock = 475"
' ?" i5 2500k mild OC = 503"
' ?" i7 3770k mild OC = 525 * estimated "
' ?" Best CPU 5Ghz OC = 590 * estimated available in 2012ad"
' ?" 6 core 12 thread = 6250 Total @5ghz OC summing all cores\threads"
' ?
' ?" Dual cores total = 400 to 900 typical"
' ?" Quad cores total = 1200 to 2000 typical"
' ?" Hex + HT total = 1500 to 4500 typical"
' ?" Death Run on L'N = 5000 to 7000 typical"
Code: Select all
'ply calculator
dim x as ulongint
x=25
screen 19
?
?" Ply calculator, there are typicaly 25 moves possible "
?
?" a ply refers to one turn taken by one of the chess players."
?
?
?
?" permutations when move options = 25"
?
? " 1 ";x
? " 2 ";x*x
? " 3 ";x*x*x
? " 4 ";x*x*x*x
? " 5 ";x*x*x*x*x
? " 6 ";x*x*x*x*x*x
? " 7 ";x*x*x*x*x*x*x
? " 8 ";x*x*x*x*x*x*x*x
? " 9 ";x*x*x*x*x*x*x*x*x
? " 10 ";x*x*x*x*x*x*x*x*x*x
?
?
?
x=30
?" permutations when move options = 30"
?
? " 1 ";x
? " 2 ";x*x
? " 3 ";x*x*x
? " 4 ";x*x*x*x
? " 5 ";x*x*x*x*x
? " 6 ";x*x*x*x*x*x
? " 7 ";x*x*x*x*x*x*x
? " 8 ";x*x*x*x*x*x*x*x
? " 9 ";x*x*x*x*x*x*x*x*x
? " 10 ";x*x*x*x*x*x*x*x*x*x
sleep : end
Free Memory Calculator memory usage quickly gets out of hand. A few gigs is woefully insufficient so it has to be managed.
Code: Select all
dim mem as ulongint
color 7
mem = FRE
?
?
?
color 10
? " MB = "; mem \ (1024 * 1024); " "
color 8
?
?
?
?
? " Free Memory "; FRE
?
? " bytes "; mem
?
? " kilobytes "; mem \ 1024; " "
?
? " megabytes "; mem \ (1024 * 1024); " "
sleep: end
speed test version 9 with results table for comparison
Code: Select all
'speed test version 9
dim i as ULONGINT
dim mem as integer
dim st as double
dim fin as double
dim mips as double
dim q as integer
color 13
?
?" Speed test9.exe"
color 7
input "...hit enter to start";q
mem = FRE
color 12
?:?" Free memory:" ;mem \ (1024 * 1024); " megabytes"
color 7
?:?" starting Free Basic speed test......approx 10 seconds":?:sleep 100
st = TIMER :?" start "; st , timer
for i = 1 to 2500000000:next i
fin = TIMER :?" finish "; fin , timer
?: color 13: ?" time = " ;fin-st;" i = ";i;" how many loops done in total"
i=i/1000000
mips = i/ (fin-st)
?:?" mips = "; mips; " FreeBASIC for next loop instructions X 1 million"
screen 19
color 13
?
?" Speed test9.exe RESULTS TABLE"
color 12
?
?" Your core speed ="; mips;" FreeBasic for next loops x 1 million"
color 7
?
?" This just tests a single core / thread"
?" Multiple core/thread efficency is approx = 90%"
?" eg an i5 2500k core = 503 then 4 cores no HT = approx 1850"
?
color 7
?" 500 Mhz Pent III = 68"
?" Celeron 2600 = 180"
?" Sepmron 2600+ = 305"
?" Athalon 2000+ = 330"
?" Atom N450 2 core = 235 * task manager cpu usage was showing 50% "
?" Atom N450 2 core = 335 * running 2 progs at once cpu usage 100% "
?" AMD XII 250 = 375"
?" AMD FX-8 8350 = 400 * estimated"
?" i5 2500k stock = 475"
?" i5 2500k mild OC = 503"
?" i7 3770k mild OC = 525 * estimated "
?" Best CPU 5Ghz OC = 590 * estimated available in 2012ad"
?" 6 core 12 thread = 6250 Total @5ghz OC summing all cores\threads in theory"
?
?" Dual cores total = 400 to 900 typical"
?" Quad cores total = 1200 to 2000 typical"
?" Hex + HT total = 1500 to 4500 typical"
?" Death Run on L'N = 4500 to 6500 typical"
?
?"...hit Enter to exit"
sleep: end
http://www.freebasic.net/forum/viewtopi ... ss#p171660
Rules of chess
http://en.wikipedia.org/wiki/Rules_of_chess
The 50 move rule is sometimes lifted for chess computers as many deep wins have been discovered. As chess computers get ever more powerful this rule will probably be abandoned altogether.
Chess Notation
http://en.wikipedia.org/wiki/Chess_notation
http://en.wikipedia.org/wiki/Forsyth%E2 ... s_Notation
http://en.wikipedia.org/wiki/X-FEN
http://en.wikipedia.org/wiki/Portable_Game_Notation
Chess Engines and ratings
http://en.wikipedia.org/wiki/Chess_engine
Online Nalimov Endgame Tablebases
http://www.k4it.de/index.php?topic=egtb&lang=en
>>>> PART ONE <<<< create a file called "startposition.txt" and display that data it in a simple board format
Code: Select all
'creates a file called "startposition.txt"
'fbnetchess1.bas
dim as integer i,ii,x,y,c,col
dim as string q,qq
dim title as string
dim special as string
dim notes as string
dim id(32) as string 'name
dim xx(32) as integer ' x cordinate A to H on chessboard as is
dim yy(32) as integer ' y cordinate 1 to 8 on chessboard displayed inverted
dim mo(32) as integer
' intitalize arrays to save start position to file
id(1)= "K" :xx(1)=5:yy(1)=8
id(2)= "Q" :xx(2)=4:yy(2)=8
id(3)= "R" :xx(3)=1:yy(3)=8
id(4)= "R" :xx(4)=8:yy(4)=8
id(5)= "B" :xx(5)=3:yy(5)=8
id(6)= "B" :xx(6)=6:yy(6)=8
id(7)= "N" :xx(7)=2:yy(7)=8
id(8)= "N" :xx(8)=7:yy(8)=8
id(9)= "P" :xx(9)=1:yy(9)=7
id(10)= "P" :xx(10)=2:yy(10)=7
id(11)= "P" :xx(11)=3:yy(11)=7
id(12)= "P" :xx(12)=4:yy(12)=7
id(13)= "P" :xx(13)=5:yy(13)=7
id(14)= "P" :xx(14)=6:yy(14)=7
id(15)= "P" :xx(15)=7:yy(15)=7
id(16)= "P" :xx(16)=8:yy(16)=7
id(17)= "k" :xx(17)=5:yy(17)=1
id(18)= "q" :xx(18)=4:yy(18)=1
id(19)= "r" :xx(19)=1:yy(19)=1
id(20)= "r" :xx(20)=8:yy(20)=1
id(21)= "b" :xx(21)=3:yy(21)=1
id(22)= "b" :xx(22)=6:yy(22)=1
id(23)= "n" :xx(23)=2:yy(23)=1
id(24)= "n" :xx(24)=7:yy(24)=1
id(25)= "p" :xx(25)=1:yy(25)=2
id(26)= "p" :xx(26)=2:yy(26)=2
id(27)= "p" :xx(27)=3:yy(27)=2
id(28)= "p" :xx(28)=4:yy(28)=2
id(29)= "p" :xx(29)=5:yy(29)=2
id(30)= "p" :xx(30)=6:yy(30)=2
id(31)= "p" :xx(31)=7:yy(31)=2
id(32)= "p" :xx(32)=8:yy(32)=2
'? xx(1)
'
'sleep :end
for i = 1 to 32 :mo(i)=99:next i
OPEN "startposition.txt" FOR output AS #1
WRITE #1,"default"
WRITE #1,"specialnull"
for i =1 to 32
WRITE # 1, id(i),xx(i),yy(i),mo(i)
next i
WRITE #1,"notes"
CLOSE #1
OPEN "startposition.txt" FOR input AS #1
input #1,"default"
input #1,"specialnull"
for i =1 to 32
input # 1, id(i),xx(i),yy(i),mo(i)
next i
input #1,"notes"
CLOSE #1
'OPEN "startposition.txt" FOR input AS #1
'input #1, title
'? title
'
'input #1,special
'? special
'
'for i =1 to 32
'input # 1, id(i),xx(i),yy(i),mo(i)
'? id(i);xx(i);yy(i);mo(i) ; "piece number ";i
'next i
'
'input #1,notes
'? notes
'
'CLOSE #1
'sleep:end
screen 19
'draw chess board notes 'Draw String (99, 66), "Origin", 12
c=0
for i = 1 to 8
for ii= 1 to 8
c=c+1
if c = 1 then col = 27 : c=c-2 else col = 6
line (i*20,ii*20)-((i*20)+18,(ii*20)+18),col,bf
'sleep 30
next ii
c=c+1
if c = 1 then col = 7 : c=c-2 else col = 11
next i
'sleep:end
col = 31
for i=1 to 32
if i > 16 then col = 0
draw string ((xx(i)*20)+6,(yy(i)*20)+2),id(i),col
'? xx(i),i : sleep
'sleep 150
next i
sleep:end
Code: Select all
"default"
"specialnull"
"K",5,8,99
"Q",4,8,99
"R",1,8,99
"R",8,8,99
"B",3,8,99
"B",6,8,99
"N",2,8,99
"N",7,8,99
"P",1,7,99
"P",2,7,99
"P",3,7,99
"P",4,7,99
"P",5,7,99
"P",6,7,99
"P",7,7,99
"P",8,7,99
"k",5,1,99
"q",4,1,99
"r",1,1,99
"r",8,1,99
"b",3,1,99
"b",6,1,99
"n",2,1,99
"n",7,1,99
"p",1,2,99
"p",2,2,99
"p",3,2,99
"p",4,2,99
"p",5,2,99
"p",6,2,99
"p",7,2,99
"p",8,2,99
"notes"
Loading the data back into the main program
Code: Select all
'load position
'fbnetchess1.bas
'using computer notation not chess notation for x,y coordinates to avoid confusion while codeing
dim as integer i,ii,x,y,c,col
dim as string q,qq
dim title as string
dim special as string
dim id(32) as string 'name
dim xx(32) as integer ' x cordinate A to H on chessboard as is
dim yy(32) as integer ' y cordinate 1 to 8 on chessboard displayed inverted
dim mo(32) as integer
dim notes as string
OPEN "startposition.txt" FOR input AS #1
input #1, title
? title
input #1,special
? special
for i =1 to 32
input # 1, id(i),xx(i),yy(i),mo(i)
? id(i);xx(i);yy(i);mo(i) ; " piece number ";i
next i
input #1,notes
? notes
CLOSE #1
'sleep:end
screen 19
'draw chess board notes 'Draw String (99, 66), "Origin", 12
c=0
for i = 1 to 8
for ii= 1 to 8
c=c+1
if c = 1 then col = 27 : c=c-2 else col = 6
line (i*20,ii*20)-((i*20)+18,(ii*20)+18),col,bf
'sleep 30
next ii
c=c+1
if c = 1 then col = 7 : c=c-2 else col = 11
next i
'sleep:end
col = 31
for i=1 to 32
if i > 16 then col = 0
draw string ((xx(i)*20)+6,(yy(i)*20)+2),id(i),col
'? xx(i),i : sleep
'sleep 150
next i
sleep:end
Notes
*human chess notation is something that computers know nothing off and so it has to be converted. Trying to debug code with human chess notation is a nightmare as the board can flip, you have to remember whose turn it is and also try and convert A1 to A4 into x,y coordinates which are opposite or inverse to screen x,y. So for the sake of my sanity this is why im just going to forget that human chess notation exists for now and i will just attend to that minor graphical detail once the program is completed.
The Next step
The next step is to flesh out all the flags and switches which will be required for the engine to decipher the board correctly. Eg whose turn is it, what move number are we on, load the previous move history into if any into an array etc.