Re: [P4wn-chess] chess rules only
Brought to you by:
dbagnall
From: Douglas B. <do...@pa...> - 2012-03-23 09:43:45
|
On 16/05/11 06:35, Adrian Dusa wrote: > Dear all, > > Very new to JavaScript, yet very amazed by the efficiency of this > chess code. It is simply tiny, something I value very much. > > I need to ask if it would be possible to strip out the AI, and > preserve only the checking for legality of chess moves. > I am building a toy chess interface in my own webpage, and all I need > is this a function which returnes true/false if a move is correct or > not. > > Ideally, this should be a single function with (I imagine) the > following parameters: fromsquare, tosquare, piece. hi Adrian, The function you might be looking for is called mv() in the 5/6k versions and p4_move() in the newly updated src/engine.js. However they have a concept of an ongoing game, so you don't need to tell it the piece. It knows that from the 'fromsquare'. For the 5k/6k function mv(s,e,b), s and e are the start and end points, using the 120 element flat array indexing described in the README at https://github.com/douglasbagnall/p4wn/blob/master/README.rst (look for "Board structure"). b is (I think) a number indicating the desired pawn promotion, with 0 or 1 meaning queen -- I can't remember which -- then bishop, knight, rook. The expanded version goes p4_move(state, s, e). s and e are as before, while state represents the entire board and carries the promotion choices within it. It really isn't possible to check the legality of a move without the context of a game, and there isn't much to be strip out if you want to keep a validity checker. The "AI" simply consists of looking through legal moves and seeing which ones end up grabbing the most stuff. In case you haven't been following the list today, development has moved to git. See http://p4wn.sf.net for further details. Douglas |