Click here to Skip to main content
15,901,205 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: It's about chess... Pin
908236511-Jan-16 4:05
908236511-Jan-16 4:05 
GeneralRe: It's about chess... Pin
F-ES Sitecore11-Jan-16 4:15
professionalF-ES Sitecore11-Jan-16 4:15 
GeneralRe: It's about chess... Pin
Kornfeld Eliyahu Peter11-Jan-16 4:21
professionalKornfeld Eliyahu Peter11-Jan-16 4:21 
GeneralRe: It's about chess... Pin
W Balboos, GHB11-Jan-16 5:28
W Balboos, GHB11-Jan-16 5:28 
GeneralRe: It's about chess... Pin
Slacker00711-Jan-16 5:59
professionalSlacker00711-Jan-16 5:59 
GeneralRe: It's about chess... Pin
dandy7211-Jan-16 7:12
dandy7211-Jan-16 7:12 
GeneralRe: It's about chess... Pin
F-ES Sitecore11-Jan-16 22:18
professionalF-ES Sitecore11-Jan-16 22:18 
GeneralRe: It's about chess... Pin
PIEBALDconsult11-Jan-16 18:44
mvePIEBALDconsult11-Jan-16 18:44 
Ah, chess...

I think about it once in a while. Remember this question from October? The Lounge - CodeProject[^]

I think of it this way:

0) There are sixty-four spaces on a chess board
1) Each space may be unoccupied or occupied by one token (I'll try not to say "piece")
2) There are six types of token: King, Queen, Bishop, Knight, Rook/Castle, Pawn
3) There are two colors of token: Black, White (usually)
4) That makes twelve distinct token values, plus we can use a "null" token to represent an empty space, for a total of thirteen values

I chess position can therefore be reduced to a sixty-four digit base-13 value.
Windows calculator calculates 13^64 as 1.9605347643076107333065976042357e+71 .
A great many such values will not represent a valid chess position.

So all you need to do is enumerate from zero to 1.9605347643076107333065976042357e+71, eliminate the invalid values and determine a pair of "best next position" values (one for black, one for white), and store them. Then during a game, a simple look-up is all that is needed to select your move.

It becomes boring really; hardly any challenge at all.

Here's what I wrote in October; this is the hard part:

C#
[System.ComponentModel.DescriptionAttribute("Chess piece definition")]
public enum Piece
{
    [System.ComponentModel.DescriptionAttribute("No piece, empty square")]
    None = 0
,
    [System.ComponentModel.DescriptionAttribute("Piece has a special or limiting movement rule")]
    SpecialMask = 1
,
    [System.ComponentModel.DescriptionAttribute("Piece can move only in ranks or files")]
    OrthogonalMask = 2
,
    [System.ComponentModel.DescriptionAttribute("Piece can move diagonally")]
    DiagonalMask = 4
,
    [System.ComponentModel.DescriptionAttribute("Black chess piece")]
    BlackMask = 8
,
    [System.ComponentModel.DescriptionAttribute("Knight")]
    Knight = 1
,
    [System.ComponentModel.DescriptionAttribute("Rook")]
    Rook = 2
,
    [System.ComponentModel.DescriptionAttribute("Pawn")]
    Pawn = 3
,
    [System.ComponentModel.DescriptionAttribute("Bishop")]
    Bishop = 4
,
    [System.ComponentModel.DescriptionAttribute("Queen")]
    Queen = 6
,
    [System.ComponentModel.DescriptionAttribute("King")]
    King = 7
}


WTF | :WTF:
GeneralRe: It's about chess... Pin
Kornfeld Eliyahu Peter11-Jan-16 20:41
professionalKornfeld Eliyahu Peter11-Jan-16 20:41 
GeneralRe: It's about chess... Pin
H.Brydon12-Jan-16 6:10
professionalH.Brydon12-Jan-16 6:10 
GeneralRe: It's about chess... Pin
PIEBALDconsult12-Jan-16 12:17
mvePIEBALDconsult12-Jan-16 12:17 
GeneralRe: It's about chess... Pin
H.Brydon13-Jan-16 5:25
professionalH.Brydon13-Jan-16 5:25 
GeneralRe: It's about chess... Pin
PIEBALDconsult13-Jan-16 10:03
mvePIEBALDconsult13-Jan-16 10:03 
GeneralRe: It's about chess... Pin
Nueman11-Jan-16 18:57
Nueman11-Jan-16 18:57 
GeneralRe: It's about chess... Pin
PIEBALDconsult12-Jan-16 12:19
mvePIEBALDconsult12-Jan-16 12:19 
GeneralI heard that Leslie and David were good friends Pin
Slacker00711-Jan-16 3:54
professionalSlacker00711-Jan-16 3:54 
GeneralRe: I heard that Leslie and David were good friends Pin
908236511-Jan-16 4:27
908236511-Jan-16 4:27 
GeneralLeslie Nielsen Pin
Mike Hankey11-Jan-16 3:30
mveMike Hankey11-Jan-16 3:30 
GeneralRe: Leslie Nielsen Pin
Mark Parity11-Jan-16 3:41
Mark Parity11-Jan-16 3:41 
GeneralA new area in history... Pin
Kornfeld Eliyahu Peter11-Jan-16 2:24
professionalKornfeld Eliyahu Peter11-Jan-16 2:24 
GeneralRe: A new area in history... Pin
KarstenK11-Jan-16 2:58
mveKarstenK11-Jan-16 2:58 
GeneralRe: A new area in history... Pin
Rage11-Jan-16 3:23
professionalRage11-Jan-16 3:23 
GeneralRe: A new area in history... Pin
Nagy Vilmos11-Jan-16 3:26
professionalNagy Vilmos11-Jan-16 3:26 
GeneralRe: A new area in history... Pin
Mycroft Holmes11-Jan-16 14:31
professionalMycroft Holmes11-Jan-16 14:31 
GeneralRe: A new area in history... Pin
Rage11-Jan-16 3:30
professionalRage11-Jan-16 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Straw Poll

Were you affected by the geomagnetic storms this past weekend?
Communication disruptions, electrified pipes, random unexplained blue-screens in Windows - the list of effects is terrifying.
  Results   502 votes