Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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


Comment on Re: "Rites of Passage" wheel reinventing
Download Code
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.)


    ---
    demerphq

      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

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.

    --hsm

    "Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://332108]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2014-12-27 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls