We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everybody!
I'm quite new to programming, and completely new to processing.
I have written down my chess opening repertoire (with hand on paper) for a couple of moves, and thought, it would be great, if I had a simple program, that tells me, depending on the opponents move (lets say I play with white), which move I (usually) play in response.
Lets assume, you know about chess notation, if my first move is 1.e4, there are a variety of possible (legitimate) answers my opponent can play (i. e. e5, c5, d5, Sf6 and so on).
So my idea is, that I open the program, there is written "1.e4" and I type in one of the above moves. Depending on which move i write in, the program gives me the next move (that I wrote in the code) i. e. "2.Sf3".
First of all, I have no idea, if Processing is the right thing to use, as I would need something text-based, and graphics aren't of any importance.
So yesterday (with a little help from a friend, who introduced me to Processing) I tried starting writing something, but already on move 2 I have no idea how to continue, as the possibilities of moves (that I already have written down by hand) become very wide quite fast. I have no clue, how (or if ;) ) I should continue. anyway, here is, what we've written so far. It would be greatly appreciated, if you could guide me towards enlightenment :)
English is not my native language, so please don't be to hard on me, regarding grammar and spelling.
Thanks in advance,
Valt
String t = "Chess Opening Database";
String move1 = "";
String move2 = "";
String s1 = "1. e4";
String s2 = "";
String s3 = "";
int q = 1;
void setup() {
size(800, 800);
}
void draw() {
background(250);
fill(0);
textSize(15);
text(t, 50, 40, 470, 63);
textSize(11);
text(s1, 50, 80, 470, 93);
text(s2, 50, 100, 470, 103);
text(s3, 50, 120, 470, 103);
text(move1, 80, 80, 470, 112);
text(move2, 120, 80, 470, 112);
}
void keyPressed(){
if(key == ENTER)
{
if(q == 1) isValid();
move1 = "";
}
else
{move1 += key;}
}
void isValid()
{
if(move1.equals("c5"))
{
s1 += " " + move1;
s2 = "2.Sf3";
q++;
}
if(move1.equals("e5"))
{
s1 += " " + move1;
s2 = "2.Sf3";
q++;
}
if(move1.equals("d5"))
{
s1 += " " + move1;
s2 = "2.exd5";
q++;
}
}
void isValid2()
{
if(move2.equals("d6"))
{
s1 += " " + move1;
s2 = "2.Sf3";
s3 = "3.d6" + move2;
q++;
}
if(move2.equals("e5"))
{
s1 += " " + move1;
s2 = "2.Sq3";
q++;
}
}
Answers
Post a Foto of your Repertoire you've hand written please
Thanks a lot for your reply! I wasn't expecting for someone to reply so quickly, so I only have a very sketchy sketch. I try to write it down a little bit more clean, and post it tomorrow. Until then, have fun, trying to read my handwriting ;) thanks again!
I think you are lost, when you keep on hacking your data into the code.
instead try to find a data structure that holds your tree of moves and then let the program just read out the data structure.
Here is my raw attempt
the data structure is in tree which holds the human moves and the computer answer moves
in tree, the first number signifies if we are allowed to look here (0,1,2..., named as
currentPossibleHumanMovesIndex
, which is basically where you are in your tree); then comes the move DONE BY THE PLAYER. Then a;
follows.Thirdly the possible counter moves follow, each with a new signifying number (that tells you where in the tree you are next)
So this:
"0e2e4;d7d5#4;b1c6#5;g1f3#6"
says : we are at currentPossibleHumanMovesIndex 0, so only when currentPossibleHumanMovesIndex is 0 we are allowed to look in this line.When currentPossibleHumanMovesIndex is 0, let's look in the line.
When the user did enter e2e4, this is our line.
Our computer answer moves are either d7d5 OR b1c6 OR g1f3.
Let's choose one of the three randomly.
ok , let's say d7d5 has been chosen, we print that out as our official move.
BUT when we choose e.g. d7d5, it says d7d5#4, we split this up again and get
4
, meaning: currentPossibleHumanMovesIndex is now4
and we are allowed to look for the next human move that's gonna be entered next ONLY in lines that start with a4
. Thus we keep track where we are in the tree.And so on.......................
thanks for posting your graph, I saw it only after posting my code
but you need just to fill your graph into
tree
new version
when you hit space bar it shows the tree
thanks a lot for your help! I'm sorry that I didn't respond yesterday, I'm a little bit stressed with studying! I really appreciate it a lot, that you put so much effort, in helping me with my idea! later today, I hopefully have time, to try your code in depth and give you some feedback/ask you some questions. However, thanks a lot, I never thought, that I would get so much help so quickly!
entire new version with two classes and you need to enter the tree step by step