/** Check if the threat sequence is still usable in that all attacker and * defender stones are still free on the given board. * * @param boardRev The reversed ([x,y]) board to be checked. * * @returns true if the threat sequence is still valid, false otherwise. */ public bool CheckValidRevBoard(int[,] boardRev) { if (boardRev[attacker.X, attacker.Y] != 0) { return(false); } foreach (GBMove gbm in defender) { if (boardRev[gbm.X, gbm.Y] != 0) { return(false); } } if (next == null) { return(true); } return(next.CheckValidRevBoard(boardRev)); }
private bool GetMoveAttack() { Console.WriteLine("GetMoveAttack"); Debug.Assert(threatsequence != null); // Check the threat sequence is still valid on the current board. // This is the rare magic case that could defeat us (C-3, C-4) if (threatsequence.CheckValidRevBoard(board) == false) { statusStr.Append("magic :-(, "); Console.WriteLine("Winning threat sequence not valid anymore, magic case."); threatsequence = null; state = MoveState.Normal; return(true); } // Also check if there is still attacker moves left if (threatsequence.attacker == null) { threatsequence = null; statusStr.Append("seqEnd reached"); state = MoveState.Normal; return(true); } // Check the last move of the opponent is one of the expected defender // moves in our threat sequence. If it is not, fall back on // alpha-beta search. if (lastAppliedThreatSequence != null && lastAppliedThreatSequence.defender != null) { bool defendedThreat = false; foreach (GBMove gbm in lastAppliedThreatSequence.defender) { if (gbm.X == lastoppmove.X && gbm.Y == lastoppmove.Y) { defendedThreat = true; break; } } // If the threat was not defended against, fall back to alpha-beta if (defendedThreat == false) { statusStr.Append("not defended, "); threatsequence = null; state = MoveState.Normal; return(true); } statusStr.Append("defended, "); } // Check if the move is in the interesting fields, which basically // asserts us there is no opponent threat we have to respond to. ArrayList fields = fieldagent.ReallyInterestingFields(board, 1); Coordinate wantmove = new Coordinate(threatsequence.attacker.X, threatsequence.attacker.Y); if (fields.Contains(wantmove)) { Console.WriteLine("Move is chosen from sequence"); bestfield = wantmove; statusStr.Append("move ({0},{1}) from seq, ", wantmove.X, wantmove.Y); sequence_used = true; lastAppliedThreatSequence = threatsequence; // Advance to next threat threatsequence = threatsequence.next; // End of sequence -> fall back to alpha beta, for the _next_ // move. if (threatsequence == null) { state = MoveState.Normal; } } else { Console.WriteLine("Move from sequence is not in interesting fields"); sequence_used = false; statusStr.Append("move not from seq, "); bestfield = DoABMove(); } // Move made return(false); }