Ludii Forum
How to update the score? - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Game Problems (https://ludii.games/forums/forumdisplay.php?fid=17)
+--- Thread: How to update the score? (/showthread.php?tid=1624)



How to update the score? - Alain Busser - 07-26-2023

Hello, I programmed this game:

Code:
(game "alquerkonane"
    ("TwoPlayersNorthSouth")
    (equipment
        {
         (board (rectangle <Rows:num> <Columns:num>))
            (piece "Ball"
                Each
                (if (no Moves Mover)
                    (addScore Prev 1)
                    (or
                        (move Step (directions { BL BR }) (to if:(is Empty (to))))
                        (move
                            Hop
                            (between
                                if:(is Enemy (who at:(between)))
                                (apply (remove (between)))
                            )
                            (to if:(is Empty (to)))
                        )
                    )
                )
            )
       }
    )
    (rules
        (start
            {
                (set Score Each 0)
                (place
                    "Ball2"
                    (intersection
                        (sites Phase 0)
                        (expand (sites Bottom) steps:1)
                    )
                )
                (place
                    "Ball1"
                    (intersection
                        (sites Phase 1)
                        (expand (sites Top) steps:1)
                    )
                )
            }
        )
        (play (forEach Piece))
        (end (if
                    (and
                        (no Moves Mover)
                        (no Moves Next)
                    )
                    (result Mover Win))
                )
    )
)

(option "Rows" <Rows> args:{ <num> }
    {
    (item "2" <2> "The board has 2 rows.")
    (item "3" <3> "The board has 3 rows.")
    (item "4" <4> "The board has 4 rows.")*
    (item "5" <5> "The board has 5 rows.")
    (item "6" <6> "The board has 6 rows.")**
    (item "7" <7> "The board has 7 rows.")
    (item "8" <8> "The board has 8 rows.")*
    (item "9" <9> "The board has 9 rows.")
    (item "10" <10> "The board has 10 rows.")
    }
)
(option "Columns" <Columns> args:{ <num> }
    {
    (item "2" <2> "The board has 2 columns.")
    (item "3" <3> "The board has 3 columns.")
    (item "4" <4> "The board has 4 columns.")**
    (item "5" <5> "The board has 5 columns.")
    (item "6" <6> "The board has 6 columns.")*
    (item "7" <7> "The board has 7 columns.")
    (item "8" <8> "The board has 8 columns.")*
    (item "9" <9> "The board has 9 columns.")
    (item "10" <10> "The board has 10 columns.")
    }
)




(metadata
    (info
        {
        (description "Take the opponent's pieces or be the last to move a pawn.")
        (aliases {"The reunionese checkers"})
        (rules "Checkers without promotion. The winner is the last to move. One can move a pawn diagonally or hop orthogonally over an opponent's pawn, taking it.")
        (source "https://iremi.univ-reunion.fr/spip.php?article1165")
        (version "1.1.1")
        (classification "board/war/leaping/diagonal")
        (author "anonymous creole")
        (credit "Alain Busser 7/21/2023")
        (origin "This game is from Reunion Island, on 2016.")
        }
    )
    (graphics (board  Style Chess))
)


and as I would like to find an AI based on the number of free moves for the winner, I added a score to each player, so that
  • The game is not ended when one player (the loser) has no moves, but when no player has no moves at all.
  • Until the game is ended, every time a player cannot move, he increments the other player's score.
For this purpose, I did

Code:
(if (no Moves Mover)
                    (addScore Prev 1) (or ...))

and it almost works. Sometimes when the loser passes the other one gets one more point on his score. Sometimes... but not always! For examples if each player uses an alpha-beta pruning the game ends like this:

Code:
Turn 24. B4-C5
Turn 25. Pass
Turn 26. C3-B4
Turn 27. .
Turn 28. B4-A5
Turn 29. Pass
Turn 30. C5-B6
Turn 31. .
Turn 32. Pass

Sometimes there is "Pass" and sometimes there is only a dot. The score is not incremented when there is "Pass". So I guess I need to pass on Pass, but I did not find out how I could do that.

Any idea?


RE: How to update the score? - Michael - 07-26-2023

I'm not one of the developers, and I don't know why this happens, but here is something else to try while waiting for an answer: Use (not (can Move …)) instead.


RE: How to update the score? - dale walton - 07-27-2023

Might have to do with who is "Prev" if the last move was a pass?
You could try (addScore (player (- 3 (mover))) 1)

The system supplied passes may skip all execution given that no move is possible, so you may need to allow an explicit pass move. Since this is meant as a forced situation, use (priority) instead of (or) to offer it

Possibly like this: - (move Pass (then ....)) might also work.

(priority
(... the normal move ... ))
(do
(addscore Next 1)
next:(move Pass)
))

Since passing becomes a move in this scenario the end condition cannot be (no Moves ...)
You would need to use (all Passed)

There may be other ways to accomplish this.

However, if you haven't set score as a weighted heuristic I don't think the AI will pay attention anyway, as the score is not part of the winning condition.
If you do set score as a heuristic in the AI definition, you may need to have some other heuristic to balance it, for cases where a player gets blocked and later unblocked for example.


RE: How to update the score? - fuerchter - 07-27-2023

Hi, here's an updated .lud using dale's suggestions. And here is a comparison of the changes made. Notes:
1. I changed ("TwoPlayersNorthSouth") so players could move forwards instead of backwards. I assume you wrote it like this because of a confusion between where players are facing versus where their starting position is? If this is not the case, feel free to change it back.
2. I added a condition "(if (= (score Mover) 0) ..." to (addScore) because otherwise the winner's final pass would always give their opponent score 1. EDIT: Having thought about this again, I think it'd make more sense if you replace this with "(if (not (all Passed)) (addScore Next 1))"
3. I changed the ending because in combination with dale's (priority) suggestion the old ending would lead to draws.

As dale said, the AI likely won't play to optimize that score though.