douglasbagnall / p4wn

a smallish turn-of-the-century javascript chess engine
http://p4wn.sf.net
113 stars 33 forks source link

A few questions #19

Closed ngdaddikar closed 8 years ago

ngdaddikar commented 8 years ago

Hi,

I am developing a program for kids and I have a couple of questions:

(1) Can the engine tell me that it is pointless to play when say a K and K & B is available?

(2) Does the findmove function store it's "findings" in the state? The code in display.js is:

    mv = state.findmove(depth);
    var delta = Date.now() - start_time;
    p4_log("findmove took", delta);
    if (P4WN_ADAPTIVE_LEVELS && depth > 2){
        var min_time = 25 * depth;
        while (delta < min_time){
            depth++;
            mv = state.findmove(depth);
            delta = Date.now() - start_time;
            p4_log("retry at depth", depth, " total time:", delta);
        }
    }

For example: Is it stronger to call findmove(5) or call findmove(3) maybe 3 times.

(3) Can I know any any point whether the position is a mate or a draw?

Thanks.

douglasbagnall commented 8 years ago

hi, This isn't really the place for this -- the mailing list would be better. If you are using issues, make it one question per issue. Anyway:

(1) Can the engine tell me that it is pointless to play when say a K and K & B is available?

If you are talking about “draw by insufficient material”, then yes. Draw is indicated by the state.move() return value as normal.

(2) Does the findmove function store it's "findings" in the state? For example: Is it stronger to call findmove(5) or call findmove(3) maybe 3 times.

I'm not quite sure what you mean by the second bit, but the answer to the first is no. But don't worry about it: there is on average something like a 30-fold increase in processing for each increase in depth. If it takes 1ms for findmove(3), it will take 30ms for findmove(4), so findmove(3); findmove(4) will take 31ms. The waste of doing findmove(3) is negligible, and so would the gain of saving its state.

(3) Can I know any any point whether the position is a mate or a draw?

It does when you make a move. If you need to know without making a move, you could put something together using p4_findmove(), which can be coerced into giving you an extreme score for checkmate or stalemate -- then p4_check_check() can distinguish between them.