FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Blayne's Multiplayer Chess Engine (Completed! Dec-9) (Page 2)

  This topic comprises 3 pages: 1  2  3   
Author Topic: Blayne's Multiplayer Chess Engine (Completed! Dec-9)
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
Chess notation (algebraic, not descriptive) uses N for knights.

Edit: Descriptive uses Kt, but no one (except old people) uses descriptive anymore.

Edit2: And PLEASE, I am begging you, change C to R.

Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
The Flying Dracula Hair
Member
Member # 10155

 - posted      Profile for The Flying Dracula Hair   Email The Flying Dracula Hair         Edit/Delete Post 
But they're little castles, they're all castle shaped.
Posts: 299 | Registered: Jan 2007  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
I'm sure it could be much shorter, but even so it underscores the usefulness of logic programming, where the code for determining if someone is in check would be under a dozen lines, maybe just two or three (depending on how certain other parts were written).
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
well I had to account for when white/black is playing after all a castle cant put you in check if its on your team.
IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
That should not take up significant numbers of lines.

There are a number of possible ways to check for being in check, but consider this one:

Iterate over, starting with the nearest, ever space in a row with the King. If you 'run into' an enemy piece, check if it could legally move to where the King is (and thus take it). If it can, the King is in check. If you 'run into' a piece that can't take the King, stop checking. Do the same for diagonals. Also, check knight positions relative to the King.

There are more efficient ways, but they would have required you to structure your other code differently. That way should work with how you're working currently, with minimal changes.

Check mate, now, that's a little harder, because you have to determine if any move could result in the King not being in check. However, the total number of possible moves for all pieces on one side in a single turn is really pretty small, and hopefully your code is structured such that you can get all current legal moves for a piece from an iterator. Then just check if the King is in check in the position that would result. If you wanted to be more sophisticated, start by checking if the piece that could previously check the King can still check the King, since most moves will be irrelevant to the original check situation.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
"But they're little castles, they're all castle shaped."

But the name of the piece is rook.


Blayne, when including rules about castling, one must remember that one cannot castle if one is in check, one cannot castle through check, and one cannot castle if either the rook or the king has moved. As well, don't forget both long castling and short castling.

Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
were not including castling into our chess game it is a class project not us trying to emulate the entire game of chess it wont award us extra marks it is not worth the work at this point of the year.
IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
quote:
it is a class project not us trying to emulate the entire game of chess it wont award us extra marks
Have you verified with your professor that a game that superficially resembles chess but is not actually chess will still receive full marks?
Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
If there isn't castling, promotion, en passant, etc. then it isn't chess. It is a game that is akin to chess, not chess.

Oh, I am interested in how you handled pawns only moving forward, but capturing diagonally. As well, them being able to move two squares forward on the first move but only 1 on any other (and also being able to move up only once on the first move).

Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
if ( condition ) then

return true
else if condition

return true
else if condition

return true
else

return false


[Big Grin]

code:
		switch(origin.itsType) 
{
case PAWN:
{
switch(origin.itsSide)
{
case WHITE:
{
cout << "deltay: " << deltay << endl;
cout << "aDeltay: " << aDeltay << endl;
cout << "deltax: " << deltax << endl;
cout << "aDeltax: " << aDeltax << endl;
if( (origin.itsSide == WHITE) && (origin.y == 1) )
{
if( ((deltay == 1) || (deltay == 2)) && (aDeltax==0) )
{
return true;
}
}

else if ( (deltay == 1) && (aDeltax == 1) && (target.itsType != EMPTY))
{
return true;
}
else
{
if( deltay == 1 && aDeltax == 0)
{
return true;
}
else
{
return false;
}
}
}
break;
case BLACK:
{
if( (origin.y == 6) )
{
if( ((deltay == -1) || (deltay == -2)) && (aDeltax==0) )
{
return true;
}
else
{
return false;
}
}
else if ( (deltay == -1) && (aDeltax == 1) && (target.itsType != EMPTY))
{
return true;
}
else
{
if(deltay==-1 && aDeltax==0)
{
return true;
}
else
{
return false;
}
}
}
break;
}

}
break;


IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Well, that's just plain wrong. There are three mistakes just in the handling of the white pawns.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
*cough* If I were you I would just steal some open source code.

Edit: I believe GNU is free and open source... just to get some ideas.

Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Beg your pardon, I shouldn't glance hastily at code like that. Six mistakes in the handling of white pawns.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
It isn't as bad as it might be, but your life will be much, much better if you learn how to really use object oriented and functional programming. You're never going to have to look at this code again after this project, but if you did, you would hate your previous self.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
KoM: well, it depends on how you count mistakes.

Blayne: I see you still haven't looked into my question about taking your own pieces.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
I am ruining it now, but at the time I posted this the topic had 64 posts. Just thought I would point that out.
Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Yeah, ok, he makes the same mistake in two different places, fair enough. I counted that as two.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
I like the redundancy, myself.

JH: he shouldn't be using open source code for a school project unless explicitly authorized to do so.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
It was a joke.
Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
There's a case above the code I posted that had a case select to make sure you werent taking your own pieces, testing has shown this works.
IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Blayne: tell me, if a pawn tries to move one space forward into a space occupied by an enemy, when it isn't in its starting row, what happens?
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
*sigh* you just have to nitpick.

It takes the pawn [Frown]

IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
It isn't nitpicking, it is showing you how reading your code with an eye to proper behavior can find bugs.

You would find your code much easier to read if it were organized more into polymorphic (in this case, that means implementing the same interface) classes (for each chess piece type, in particular). It would be much easier to debug if you wrote real test cases.

For instance, imagine if each piece had its own code that determined if a move was legal. It would probably be passed the board as an argument. Then you wouldn't have your monolithic move method of doom, and you could write simple checking code that constructed a contrived board and tested if a piece could make various moves.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Dude, fugu, let's concentrate on understanding game logic before we get into good programming practice, eh? One thing at a time.

What happens if someone tries to attack with a pawn that hasn't moved yet?

What happens if someone moves a pawn into, or through, an occupied space? (This is three mistakes in one sentence.)

What happens if someone attacks their own piece?

What happens if someone tries to move a pawn off the board? That's quite without going into pawn promotion, mind you.

I won't even get into attacking en passant.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
He apparently tackles the 'attack their own piece' with an earlier check, as he communicates above. I assume it just checks if the proposed destination space has a friendly piece.

I would hope he has a check against dy ever going over the size of the board (and the UI might not allow such a move, making the question essentially moot, good as it would be to guard against in the API).

However, it really isn't the game logic that's important. As we can see from his response, Blayne pretty much gets the game logic, it is translating all that knowledge into programming logic that is the issue. He seems to still be viewing programming flow as somewhat of a black box, albeit one he can tinker with and hope it works.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
Blayne, I don't know what what level your class is... Have you studied OOP? Polymorphism and inheritance? Or is this a straight up pseudo-C++ assignment with only functions and scalar/vector object types?

*EDIT* This is gonna make me end up writing one just because I can... Thanks for distracting me, Blayne! ***sigh...***

[ December 03, 2007, 08:46 AM: Message edited by: Nighthawk ]

Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
quote:
Originally posted by fugu13:
However, it really isn't the game logic that's important. As we can see from his response, Blayne pretty much gets the game logic, it is translating all that knowledge into programming logic that is the issue.

I disagree, or perhaps I emphasize differently; the first step must be to really understand all the possible game-logic cases, which he clearly doesn't. At least, he hasn't thought about them thoroughly. Programming is relatively trivial if you really understand what's going on; so to translate into programming logic, you have to really think about the game logic, what's possible, and what's not. I think that's the important step that's missing, not knowledge of OOP and whatnot. If you can do X in procedural, it's pretty simple to pick up the OOP way of doing it. But to understand the procedural you have to learn the programming-oriented way of thinking about the problem, which is to understand all the edge cases and step through all the branches yourself. Not that attacking with an unmoved pawn is an 'edge' case, by any means!
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
When my partner saw my check code he was like "jesus christ this is alot of code, its awesome"

followed by "wow it follows indentiation perfectly"

IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
Just because your partner says it is good does not mean that it is good.

No offense intended, but I suggest that you listen to what these people are advising you of, since it is evident that they know more about programming than you. You can't just ignore rules of chess and call it chess.

Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
MattP
Member
Member # 10495

 - posted      Profile for MattP   Email MattP         Edit/Delete Post 
I think he was saying that his partner was marveling only at its indentation (or "indentiation", if you prefer), not at its quality.
Posts: 3275 | Registered: May 2007  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
I think your partner is following the excellent rule of being quiet if you can't say anything nice. Praising the indentation is really the last resort of someone determined to find something to compliment.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
El JT de Spang
Member
Member # 7742

 - posted      Profile for El JT de Spang   Email El JT de Spang         Edit/Delete Post 
I myself am known in some circles for writing long, utterly useless, but perfectly indented, code.
Posts: 5462 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Since doing the indentation is really an absolute minimum requirement for an IDE, it doesn't exactly reflect well on the developer.
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
quote:
Originally posted by El JT de Spang:
I myself am known in some circles for writing long, utterly useless, but perfectly indented, code.

That in your job description, too? I've got millions of lines of code that look immaculate!

And you didn't answer my question:

quote:
Blayne, I don't know what what level your class is... Have you studied OOP? Polymorphism and inheritance? Or is this a straight up pseudo-C++ assignment with only functions and scalar/vector object types?

Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Coulda swore I posted but we do some OOP, mostly structures/classes/function, next semester we do OOP in detail.

In related news I think I got screwed over by my partner, he's decided to bail and is refusing to send me the latest version of the project we were working on.

IP: Logged | Report this post to a Moderator
ricree101
Member
Member # 7749

 - posted      Profile for ricree101   Email ricree101         Edit/Delete Post 
quote:
Originally posted by Blayne Bradley:
Coulda swore I posted but we do some OOP, mostly structures/classes/function, next semester we do OOP in detail.

Correct me if I'm wrong, but aren't you fairly close to graduating?
Posts: 2437 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
Dagonee
Member
Member # 5818

 - posted      Profile for Dagonee           Edit/Delete Post 
quote:
In related news I think I got screwed over by my partner, he's decided to bail and is refusing to send me the latest version of the project we were working on.
What reason does he give for bailing and refusing to send you the latest version.
Posts: 26071 | Registered: Oct 2003  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Maybe he looked more closely at the splendid indentation, and noticed that the if-then constructs are inconsistent with how they use braces. I would definitely bail from any partner who couldn't keep his braces consistent. :nods:
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
no he always had the impression I wasn't keeping up with my end of the work, (when codewise I wrote about twice as much code and was responsible for debugging his mistakes), now he didn't state this as his reason azs he just kinda yelled something about giving up and soemthing else I couldnt make it from down the hall way, I followed him not quite understanding asking if hes going to email me the laest version fo the header so I could fix the latest problem that came up, and he said no and asked for me to guess as to why.

I can only assume his reason is that I am somehow not keeping up when I have been.

OOP is a dedicated course next semester which is the final one as well.

I already talked to my teacher about this he said to do as much as I can do for tuesday and he'll figure something out.

IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
*facepalm*
Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
I suspect you two have had differing expectations, and that this is due to a gigantic communication gulf.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
COMPLETED COMPLETED COMPLETED COMPLETED!


[Party] [Party]

[Party]
[Party]


Woohhooo!!!!!

Source code and exe's

IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
So umm, how do I open it?
Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
you need linux. and I havent gotten a harddrive thats works yet so I havent been able to make my own, and I am a tad antsy about giving out my linux server account online.
IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
Did you fix all the problems mentioned earlier?
Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
My biggest problem with getting networking to work, was that the code I wa susing would only send packets where the message was a string buf[MAXDATASIZE+1], [Frown] so I had to make a whole new function that would convert the ASCII value of a char to its related integer.

I put it in a separate headerfile ascii.h because I felt it would be neater.

IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
If by problems you mean making it correspond to Official 10.6.7.8.9.1-c rule of Chess as you see it hell no, if you mean by odd things like a pawn taking a pawn right infront of it yes.

Although I have determined that I also lacked the time and energy to check if by moving a non-king piece will it put me in check because the way I wrote my check function I'ld need a roll back function or completely rewrite my 400 line of code blob to get it to work right.

Case 1:

Move pawn, castle now checks king, rollback move declare invalid.

case 2: adjust the valid move segment of every single possible case to include a new case of "if I move will it put the King in check?" in some way that manages to figure out that it shouldnt include itself as a blocking piece since it will move otherwise.

IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
Can a king move next to another king?
Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
nope, I check for that.
IP: Logged | Report this post to a Moderator
Itsame
Member
Member # 9712

 - posted      Profile for Itsame           Edit/Delete Post 
Can a pawn promote?
Posts: 2705 | Registered: Sep 2006  |  IP: Logged | Report this post to a Moderator
  This topic comprises 3 pages: 1  2  3   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2