Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 27th, 2003, 09:03 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
Checkmate algorithm

I've made a 2 player chess game to be played over tcp/ip. i saved the best(and hardest) part for last, writing the algorithm that finds the "check" status. as of now, one player must physically "kill" the opposing player's king(run him over and take the square) in order to win. but i would like to have the computer give a "check" warning, or the "checkmate" message. i've been pseudo coding, and this is what i have so far:

the algorithm is run on the player who has just theoretically been put in check, not the attacking player.

determine if king is "in check"
- start at king's location and using the rulesets for the movement of pieces, step thru each possible line of attack for each piece. i.e. - for rook: check all the x/y values moving away from the king until either a) a friendly piece is encountered or b) the enemy rook is-thus signifying check or c) end of board
-repeat this for each possible piece

if in check:
determine where there are open spaces to move to, then run each of these spaces thru the above algorithm recursively(i think)

if none of those spaces are valid:
can one of my own pieces sacrifice their life for me and block teh opposing piece?

-- i have a pretty good grasp on the first two steps, but the last one causes my brain to stop functioning. am i going about this the right way? anyone have any suggestions/comments? i remember someone in read had this cool link in their signature all about this, but i cant remember who u r!!!

Reply With Quote
  #2  
Old April 28th, 2003, 10:53 AM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 58 sec
Reputation Power: 12
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
I'm probably reading into your first step wrong, but it sounds like you're checking all the enemy pieces on the board to see if they can reach the king, instead of just checking what pieces have a path to the king and seeing if that path is a valid move.
For example, from the king's position, check all paths extending from him and then check if end of board, friendly player, or enemy player. If you reach an enemy then check valid move rules. Then you just need to handle the special case of knights since they can jump over pieces and have unorthodox movement. Like I said, this maybe exactly what you were describing but if not maybe this can help.

In regards to the third step, an initial thought (there's probably a better method) would be to put all paths for each piece that has the king in check into a list and then follow each square along each path and see if a friendly piece can move into that spot. (using an algorithm similar to finding out if your king is in check to). Then check if your friendly move will open up a path that will leave your king open.

Just some thoughts, not sure how viable they are.

-b
__________________
PostgreSQL, it's what's for dinner...

Reply With Quote
  #3  
Old April 28th, 2003, 01:47 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
^^heh, yes what u were describing in the first part is exactly what i was trying to explain.... my explanatory skills are lacking, my bad.

as for the second part, that's kind of along the lines of what i was brainstorming. my problem is that as of now, i dont keep track of where all teh pieces are since i previously had no need for any intelligence on the computer's side. i guess i will have to go back and add some methods/members to track at least the friendly pieces. or else i would have to loop thru the whole board to find all the friendly pieces, which would be a pain i think.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Checkmate algorithm


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT