Ludii Forum
Need info about (is Repeat Situational) - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About the Ludii Grammar (https://ludii.games/forums/forumdisplay.php?fid=15)
+--- Thread: Need info about (is Repeat Situational) (/showthread.php?tid=521)

Pages: 1 2


Need info about (is Repeat Situational) - dale walton - 03-25-2021

I need information on how this works.

I tried to create a phase to handle cases where the board position has returned to a previous state, but
{
    (nextPhase (not (is Repeat Situational)) "NormalPlay")
    (nextPhase (is Repeat Situational) "ReducePieces")
}

didn't leave any moves after the first placement, (and hangs upon passing) whereas the program had been working fine before.

Is (is Repeat Situational) always true at the end of a turn?
or are there still bugs in its implementation.

The following is the change to my FamilyOfFour game main routine. (refer to the other thread regarding hanging AI and analysis)

(game "Family of Four"
(players 2)
(equipment
  {
  (board "BoardUsed" use:Vertex)
  (piece "Piece1" P1 )
  (piece "Piece2" P1 )
  (piece "Piece3" P1 )
  (piece "Piece1" P2 )
  (piece "Piece2" P2 )
  (piece "Piece3" P2 )
  }
)
(rules
  (start (set Score Each 0))
  phases:{
  (phase "NormalPlay"
    (play
    (priority
      (or
      {
        ("AddPiece" "Piece1")
        ("AddPiece" "Piece2")
        ("AddPiece" "Piece3")
      }
      )
      ("StepPiece")
      (then
      (and
        ("CheckWinCondition")
        (set NextPlayer (player (next)) (then (moveAgain)))
    ))))
    {
    (nextPhase Next (not (is Repeat Situational)) "NormalPlay")
    (nextPhase Next (is Repeat Situational) "ReducePieces")
    }
  )
  (phase "ReducePieces"
    (play
    (forEach Piece
      (move Remove (from)
      (then
        (moveAgain)
      ))
      All
    ))
    (end
    (if
      (= 0 (count Sites in:(difference (sites Board) (sites Empty))))
      (byScore)
    ))
    {
    (nextPhase Mover (not (is Repeat Situational)) "NormalPlay")
    (nextPhase (is Repeat Situational) "ReducePieces")
    }
  )
  }
  (end
  (if
    (< 0 (score Mover))
    (byScore)
))))

The following parts were added in to see what happens, but didn't help. The problem exists without them.

(set NextPlayer (player (next)) (then (moveAgain)))

and Mover and Next in the (nextPhase ...) statements

---------------------------------------------------------------------------------
Changing to "Positional" works OK (but is not what I want....)
But "InGame" also hangs.

-------------------------------------------------------------------------------
Positional doesn't seem to be triggered by a forced Pass - Why not?

-------------------------------------------------------------------------------
The concept I am trying to implement is that if a situational repetition happens, the player in the repeated position must remove any players' pieces one at a time until the position is a new position, and following that take his normal turn.

A situational repeat in this concept included consecutive forced passes due to no moves available to either player. (which I assume should happen if the consecutive pass does not end the game...)


RE: Need info about (is Repeat Situational) - dale walton - 03-25-2021

In a workaround version, I am still getting hung AI
Here is a terminal error for the attached program and trial
Exception in thread "Thread-5" java.lang.IndexOutOfBoundsException: bitIndex < 0: -1
at main.collections.ChunkSet.clear(ChunkSet.java:496)
at game.util.equipment.Region.remove(Region.java:242)
at game.functions.region.math.Difference.eval(Difference.java:87)
at game.rules.play.moves.nonDecision.operators.foreach.site.ForEachSite.eval(ForEachSite.java:72)
at game.rules.play.moves.nonDecision.operators.logical.If.eval(If.java:131)
at game.Game.moves(Game.java:2461)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:497)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:580)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:538)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:580)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:538)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:580)
at search.minimax.AlphaBetaSearch.iterativeDeepening(AlphaBetaSearch.java:302)
at search.minimax.AlphaBetaSearch.selectAction(AlphaBetaSearch.java:178)
at util.ThinkingThread$ThinkingThreadRunnable.run(ThinkingThread.java:186)
at java.base/java.lang.Thread.run(Thread.java:834)


----------------------------------------------------
I was also trying many approaches because one of the pieces in remove situations would  often not be allowed fto be selected, even though all were in state 1. And since I assumed (forEach Piece ...(from) was working I figured there was a no move situation causing it not to select - i.e. a bug in my logic. Then I also tried using (forEach Site in state 1 instead.. and that is when I actually got a terminal error to report.  So it may be a separate or related issue.


RE: Need info about (is Repeat Situational) - dale walton - 03-25-2021

Another example possibly related or not.

In this version the AI also hangs, but playing by hand I purposely create a situational repeat.  In the script, such repeats are allowed, and should be handled by the removal code, but here the choice to play the piece causing the repeat is not offered.

(I modified the game here to remove only the opponents' piece, but this is not relevant.)  I also modified the coding to an earlier approach, so the logic is different.


RE: Need info about (is Repeat Situational) - dale walton - 03-25-2021

One more: This one gives errors in the status window.
I switched form a then construction to a do next construction.


RE: Need info about (is Repeat Situational) - dale walton - 03-27-2021

I have noticed that the (no Moves Mover) and (is Repeat Situational) are difficult to use correctly, and the Logic guide gives little guidance about the pit falls.
It seems that the system is designed to protect against recurrent situations within a given turn, and a game seeking alternative methods of avoiding cycling is very tricky to implement. For example, if any of the previos posts are not due to Ludii bugs, then the detailed reasons need to be explained as examples of how not to script, and why not.

I finally succeeded by introducing a separate decision to move again (move Set NextPlayer (player (mover)) and a fall-back pass move, and the game AI are now working, and the game complexity is not hanging, so I guess the script is now finite in a proper way.

Please refer to my next post in the submission thread.


RE: Need info about (is Repeat Situational) - DennisSoemers - 03-29-2021

(03-25-2021, 07:48 AM)dale walton Wrote: In a workaround version, I am still getting hung AI
Here is a terminal error for the attached program and trial
Exception in thread "Thread-5" java.lang.IndexOutOfBoundsException: bitIndex < 0: -1
at main.collections.ChunkSet.clear(ChunkSet.java:496)
at game.util.equipment.Region.remove(Region.java:242)
at game.functions.region.math.Difference.eval(Difference.java:87)
at game.rules.play.moves.nonDecision.operators.foreach.site.ForEachSite.eval(ForEachSite.java:72)
at game.rules.play.moves.nonDecision.operators.logical.If.eval(If.java:131)
at game.Game.moves(Game.java:2461)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:497)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:580)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:538)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:580)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:538)
at search.minimax.AlphaBetaSearch.alphaBeta(AlphaBetaSearch.java:580)
at search.minimax.AlphaBetaSearch.iterativeDeepening(AlphaBetaSearch.java:302)
at search.minimax.AlphaBetaSearch.selectAction(AlphaBetaSearch.java:178)
at util.ThinkingThread$ThinkingThreadRunnable.run(ThinkingThread.java:186)
at java.base/java.lang.Thread.run(Thread.java:834)

This stacktrace was indeed a bug in our code, I've just fixed that so that fix should be in the next release.

Any of the freezes reported in this thread are probably the same as reported in the other thread which I just responded to that is also fixed (any game that used a combination of NoRepeat and ForEach Piece would have been affected by that one).

The remaining issues reported throughout this thread are not my area of expertise, I suspect Eric will be able to take a look at them when he's back from holidays somewhere next week.


RE: Need info about (is Repeat Situational) - dale walton - 03-29-2021

Great. Thanks for looking through my various attempts and for letting me know.

I was wondering if (no Moves Mover) and (is Repeat Situational) etc, could have a when clause like remove does, so that one could specify to check at the begining of the move, after the decision, at the point of the test code execution, and/or at the end of the move.

Of course it might not be worth the effort, as this is not likely to be needed in most games, I am guessing.


RE: Need info about (is Repeat Situational) - Eric Piette - 04-06-2021

Hi,

Similarly of the other issue about repeat, I will have to check all the code about repeation. If I do that before the next release I will let you know in one of the thread you discussed about that, then please check for your game in that next release, what kind of error you still have and I will check but that probably comes from the repeat code.

Regards,
Eric


RE: Need info about (is Repeat Situational) - dale walton - 04-06-2021

Welcome back, and thanks.


RE: Need info about (is Repeat Situational) - Eric Piette - 04-13-2021

Hi Dale,

Ok with the next release, you should have the choice between situational (all data in the states) or positional (only the state data on the boards) and to look within the game or within the current turn. With:
- SituationalInTurn
- PositionalInTurn
- Positional
- Situational

The state comparison is done in comparing the Zobrish hashing value equivalent of each state, which is build with each data in the state.

In case of problems you would find for any of them from the next release, let us know and we will look if that specific data you have trouble with was not missed in the Zobrish hash value. At least for the current games using it or the tests I did, that works now.