Society of Robots - Robot Forum

General Misc => Misc => Topic started by: jamort on June 27, 2009, 02:04:55 AM

Title: Chess Game...
Post by: jamort on June 27, 2009, 02:04:55 AM
I'm in the middle of making and AI chess program in c++ and thought if you can program a chess game to beat a world chess champion what would happen if two computers play each other... with the same software... would they eventually crash?
Title: Re: Chess Game...
Post by: SmAsH on June 27, 2009, 02:11:31 AM
maybe, you would guess they would keep going and going and maybe just get into a stalemate?
Title: Re: Chess Game...
Post by: jamort on June 27, 2009, 02:27:34 AM
I would think that if one were to get put into check it would keep processing looking for a way out and i know if you do a forever loop it can cause a computer to crash... it would be an interesting thing to see.. id google it but im busy coding
Title: Re: Chess Game...
Post by: SmAsH on June 27, 2009, 02:40:21 AM
maybe, but probably unlikely to crash...
Title: Re: Chess Game...
Post by: jamort on June 27, 2009, 06:27:30 AM
I would think it would get over ran with data... because it would probably keep processing the same things over and over again
Title: Re: Chess Game...
Post by: SmAsH on June 27, 2009, 06:28:56 AM
most microcontrollers do this anyway... similar to a loop?
Title: Re: Chess Game...
Post by: jamort on June 27, 2009, 06:50:18 AM
yeah a loop that will never b tre so it keeps backing up data and i think it could cause a computer to crash IF left long enough.... because its like having this (not sure if you know c++

Code: [Select]
#include <iostream>

using namespace std;

int main()
{
    int n;
    for(n = 0; n < 100; n--){
          cout<< n << "\n";
}
}
its not a lot of data at first but with time it would start to get to be a lot
Title: Re: Chess Game...
Post by: chelmi on June 27, 2009, 09:25:34 AM
yeah a loop that will never b tre so it keeps backing up data and i think it could cause a computer to crash IF left long enough.... because its like having this (not sure if you know c++

Code: [Select]
#include <iostream>

using namespace std;

int main()
{
    int n;
    for(n = 0; n < 100; n--){
          cout<< n << "\n";
}
}
its not a lot of data at first but with time it would start to get to be a lot

Depends on what you call a crash. To me a crash is a hardware exception, a trap...
This is just a strange loop: you start at 0 and decrement. Since n is an integer, it will be negative first. The loop condition is still valid until you hit -2^(32-1) and then it will be positive and equal to (2^32)-1. The condition will be invalid and the loop will stop.

Anyway, an infinite loop by itself is not a problem. Most of your code on a microcontroller is probably inside an infinite loop. What is bad is an "out of control" loop. Like a loop that allocates memory without freeing it, or a loop that write outside the boundaries of an array and trash data everywhere, ... this will eventually cause a crash.

Regarding your initial question, it really depends on the kind of algorithm you use. I am neither a chess player nor an AI specialist, but I would guess that they would reach a point where none of them can win (is it possible with chess?) and the will continue to repeat the same pattern of move forever (called a livelock (http://en.wikipedia.org/wiki/Livelock#Livelock) in computer science). Even if they reach a livelock, and if your program is well designed (I'm sure it is ;) ), it should not crash! Another possibility would be that who wins will only depend on who was the first to move a piece.

Actually, I guess you will have to take a decision a some point in the game, like choose between several moves that are all valid and appear to be equally "clever" at this stage of the game. If you take a random choice in this case then on of your AI could choose a "not so clever" and lose the game. If you always take the same choice it could lead to the situations I mentioned above.

Hope this help!

Chelmi.
Title: Re: Chess Game...
Post by: jamort on June 27, 2009, 01:33:37 PM
yeah i got an example of one that will crash a computer... its batch coding if you just but say open file and but a label and goto command that will make a computer crash...
I'm still in a lot of the pseudo code stages... and brushing up on classes and so forth never really used that will robotic AI
Title: Re: Chess Game...
Post by: mdmedlin on June 28, 2009, 04:05:00 AM
I think that a smart program would be one with a recursive algorithm.  One that starts with every possible move (if that were possible) and narrows it down to one move that it will make.  Now because these two computers are programmed with the same library of chess possibilities, eventually, I believe that there will be a point in the recurssion that they will take seperate paths that will lead to the move they will make.  I don't think that the computer will crash, but at first it may take a while for them to figure out the first moves as the program goes through its recurssive process.
Title: Re: Chess Game...
Post by: jamort on June 28, 2009, 11:00:22 AM
Ive though up some psuedo code and for the beggining like 3 moves when i play chess if I match the other players first three moves it normally ticks them off so im going to do that..

then when it gets moving it checks to see what players can take out what hen makes a list of the rank they hold on the board and the cross checks if  the piece moved can be can be took out after that move... I'm trying to come up with a math problem to figure that out
just dpnt have it worked out...