Luis Babboni
Yes I was taking about Soberango, Numpty\NoMega has a .exe file just under 300 Kb and can processes about 2 to 3 times more nodes then your program and it still has some problems.
About debug.
The debug information is only needed when you are looking for bugs or weird behavior, it does not interfere with the working.
Also for testing you can compile with the -exx option, this adds checks for the array’s resulting in slowing the program.
Therefore when you place a program on the internet it should only be compiled with
-s console or
-s gui.
It will take some time to figure out how your program works, but I have seen somethings that need to change in order to gain more speed.
The idea of a chess program is very simple, find the best move. There are two way’s to do this.
1. Try to get as many ply’s you can in a given time and look at the value of the pieces, the move with the highest score is played.
2. Make a move and evaluate the board add points for strong positions and subtract points for bad positions.
3. A combination of the both methods.
For this speed is very important, thus using
integer’s is the best thing, other types like floats (single, double) and strings should be avoided. So using
rnd() in the move generation is as very bad thing. Getting a random number takes to much time and converting that number to an integer is also time consuming.
Playing random moves is a very bad idea, there is a change that you create a situation where your opponent can take pieces that have not enough protection and before you know it you lose the game, because you lost important pieces.
Also calling lot’s of
SubRoutine’s is waist of time, especial routine’s that only called from one places.
Better incorporate
SubRoutine’s into one. ‘MuevePeon.bas’ has several subroutine’s that should be made into one big subroutine.
DIM
From your program I can see that you have no idea what
DIM does.
(small example) From: BOOTEO.BAS
'DIMENSIONAMIENTOS:
Dim Tablero(1 To 8, 1 To 8) As Integer
What
DIM does is it claims 8*8*4 (size of integer) byte’s, and then clears the array by loading it with 0’s
Then later you have this
'Inicializa todo en 0, CargaFEN se encarga después de poner lo que debe valer:
For i=1 To 8:For j=1 To 8: Tablero(i,j)=0:Next: Next
You do something that already done, and also you a slower then FB.
If you
DIM a variable it contents is loaded with 0.
in Sub Reseteo you clear some array's
'Inicializa todo en 0, CargaFEN se encarga después de poner lo que debe valer:
For i=1 To 8:For j=1 To 8: Tablero(i,j)=0:Next: Next
Since Tablero() is shared you simple do
REDIM Tablero(1 to 8, 1 to 8).
What happens is Tablero() is removed and replaced by a new version that has it contents filled with 0’s.
To show how fast that is I have made a little program to demonstrate the principle.
Code: Select all
'compile with -s console
#Define small 10
#Define big 10000000 ' 10 000 0000
dim as integer a, b, c
Dim As Byte array()
ReDim array(big, small)
Print
Dim As Double t1 = Timer
For a = 1 To small
For b = 1 To big
array(big, small) = 0
Next
Next
t1 = Timer - t1
Print Using " small first then big: ##.######## ";t1
t1 = Timer
For a = 1 To big
For b = 1 To small
array(big, small) = 0
Next
Next
t1 = Timer - t1
Print Using " big first then small: ##.######## ";t1
t1 = Timer
ReDim array(big, small) ' As byte
t1 = Timer - t1
Print Using " redim array: ##.######## ";t1
Print : print
t1 = 12.34567
Print " normal display";t1
Print Using " Hey look automatic round off ##.##"; t1
Print Using " Hey look automatic round off ##.###"; t1
Print Using " Hey look automatic round off ##.####" ; t1
Print Using " Hey look automatic round off ##.#####" ; t1
Print
Print "hit any key to stop"
Sleep
From HaceLog.bas
Print #1, " Tiempo(s)=";Using "###.## ";Int(Tiempo*100+0.5)/100
Can be replaced with.
Print #1, " Tiempo(s)=";Using "###.## ";Tiempo
Gives the same result.
Code: Select all
Sub AlfaBeta (ByVal p As Integer, ByRef AB As Integer)
Dim par As Single 'Necesito que no sea entero para evaluar p/2
par=p
AB=1 'En principio la búsqueda debe seguir.
If p>1 And Nodo(p-1,1)=1 And par/2=Int(par/2) Then 'si p es nodo par, mueve rival.
If ColorSoberango=1 Then If Nodo(p,2)<=Nodo(p-1,2) Then AB=0 'si rival es negras corta si ve que la valuación es menor pues Soberango con blancas no la elegiría.
If ColorSoberango=-1 Then If Nodo(p,2)>=Nodo(p-1,2) Then AB=0 'si rival es blancas corta si ve que la valuación es mayor pues Soberango con negras no la elegiría.
EndIf
If p>1 And Nodo(p-1,1)=1 And par/2<>Int(par/2) Then 'si p es nodo impar, mueve Soberango.
If ColorSoberango=1 Then If Nodo(p,2)>=Nodo(p-1,2) Then AB=0 'si Soberango es blancas corta si ve que la valuación es mayor pues rival con negras no la elegiría.
If ColorSoberango=-1 Then If Nodo(p,2)<=Nodo(p-1,2) Then AB=0 'si Soberango es negras corta si ve que la valuación es menor pues rival con blancas no la elegiría.
EndIf
End Sub
AlfaBeta is called from to 2 places it would be better to replace the calls with the code itself it’s only a few lines. The code needs some alteration to fit in and to streamline the code.
par/2=Int(par/2) is not the best way to check if a variable is odd or even. Floating point division is slow and converting floaing point variables to a integer is not fast. The way to do this is
p and 1 = 1 for odd and
p and 1 = 0 for even. This method is much faster. Also the logic can be changed make it more streamlined.
If you don't understand the principals then leave it as it is, I will work some thing out when I have time.