Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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]
[shmem]: Discipulus: war/peace is a question of fuel gauge position...
[Discipulus]: yes i saw your cell brother..
[Discipulus]: but now fuel is cheap and they still make some war.
[Discipulus]: capitalism is able to go to war by cycle, even.
[shmem]: some? are you jokin' ?
[shmem]: fuel is only one fuel that fuels the fools... it is all about power and control - which NOBODY will have.
[shmem]: ...can't have, since silly

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2017-04-29 22:02 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.