Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: "Rites of Passage" wheel reinventing

by hardburn (Abbot)
on Feb 26, 2004 at 21:57 UTC ( #332108=note: print w/replies, xml ) Need Help??

in reply to "Rites of Passage" wheel reinventing

I did a chess move validator in C. Did it in the hardest, most bug prone, and least efficient way, too. (A chess board is small enough that it's practical to build a lookup table of all possible moves with O(1) efficiency, and with a pretty low constant, too. I was trying to do it on the fly.)

At the moment, I'm writing some bloging code because I don't like the way everyone else's blogging code does things. I'd use Bryar, but it doesn't seem to currently support HTML::Template, and much of my site is already written using that instead of TT.

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: "Rites of Passage" wheel reinventing
by hsmyers (Canon) on Feb 27, 2004 at 06:11 UTC

    I don't know about reinventing wheels, but I must confess to having written a chess move parser in every language I've ever learned. And truth be known, more than one version. The smallest was in lisp, the fastest in assembler---after so many years it has become a ritual, a sort of necessary task before I even pretend to 'know' the language of the moment. So I suppose I'm guilty of re-wheeling, in fact re-wheeling the same wheel. I guess I do know about reinventing wheels after all.


    "Never try to teach a pig to wastes your time and it annoys the pig."
Re: Re: "Rites of Passage" wheel reinventing
by demerphq (Chancellor) on Feb 26, 2004 at 22:03 UTC

    Im confused, how do you reckon you can lookup table all the possible moves? Maybe i misunderstand you but wouldnt that require knowing all possible games and putting all possible board positions in the lookup table? (Which I think would mean that you could solve the problem of the prefect game.)


      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi

      Nah, you just need to have a board with one piece on it and generate all possible moves for that piece from that postion. Then put that data in the lookup table and do it again for the next piece or position. You'll still have to do a little runtime work like check that the piece isn't jumping over other pieces (except for knights) and isn't landing on a square already occupied by a freindly piece, plus few other special cases (like pawn attacks). For the most part, though, lookup tables get the hard part done.

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

      I thought of this as an individual move validator. "Is this move legal?" sort of thing.
        It's a small lookup table. Just fifty billion possibilities. Nothing big :)

      Which I think would mean that you could solve the problem of the prefect game.

      <funny>All in O(1) time, and built on-the-fly!! This should be a pretty nice chunck of code...</funny>

      "In few words, translating PerlMonks documentation and best articles to other languages is like building a bridge to join other Perl communities into PerlMonks family. This makes the family bigger, the knowledge greater, the parties better and the life easier." -- monsieur_champs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://332108]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-01-23 18:54 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (253 votes). Check out past polls.