public override void Load() { try { IsEnabled = true; MoveWrapper.init(); var moveCount = MoveWrapper.getMovesCount(); if (moveCount <= 0) { IsEnabled = false; return; } MoveWrapper.setRumble(0, 255); Thread.Sleep(40); MoveWrapper.setRumble(0, 0); MoveWrapper.subscribeMoveUpdate( MoveUpdateCallback, MoveKeyDownCallback, MoveKeyUpCallback, NavUpdateCallback, NavKeyDownCallback, NavKeyUpCallback ); } catch (Exception exc) { Logger.Instance.Error(exc.Message, exc); IsEnabled = false; } }
private static void DoMoves(string[] moveTokens) { // apply moves foreach (var moveToken in moveTokens) { var move = new MoveWrapper(moveToken, _cb); _cb.DoMove(move.Move); } }
public override void Unload() { try { MoveWrapper.unsubscribeMove(); } catch (Exception exc) { Logger.Instance.Error(exc.Message, exc); } }
void MoveUpdateCallback(int id, MoveWrapper.Vector3 pos, MoveWrapper.Quaternion rot, int trigger) { RawPosition = new Vector3D(pos.x, pos.y, pos.z); RawRotation = new Quaternion(rot.x, -rot.y, rot.z, -rot.w); if (MoveWrapper.getButtonState(0, MoveButton.B_START)) { Dispatcher.Invoke((Action)(Calibrate)); } Dispatcher.Invoke((Action)(UpdatePositionAndRotation)); }
private static void DoTest(IReadOnlyCollection <string> epdStrings) { var correctCounter = 0; foreach (var epdString in epdStrings) { var epd = new Epd(epdString); var cb = ChessBoardInstances.Get(0); ChessBoardUtil.SetFen(epd.GetFen(), cb); TimeUtil.Reset(); TimeUtil.SetSimpleTimeWindow(5000); SearchUtil.Start(cb); var bestMove = new MoveWrapper(ThreadData.GetBestMove()); if (epd.IsBestMove) { if (epd.MoveEquals(bestMove)) { Console.WriteLine(epd.GetId() + " BM OK"); correctCounter++; _positionTestOk++; } else { Console.WriteLine(epd.GetId() + " BM NOK " + bestMove + " - " + epd); _positionTestNok++; } } else { if (epd.MoveEquals(bestMove)) { Console.WriteLine(epd.GetId() + " AM NOK " + epd); _positionTestNok++; } else { Console.WriteLine(epd.GetId() + " AM OK"); correctCounter++; _positionTestOk++; } } } Console.WriteLine(correctCounter + "/" + epdStrings.Count); }
private static bool MoveEquals(string moveString, MoveWrapper bestMove) { var move = bestMove.Move; var sourceIndex = MoveUtil.GetSourcePieceIndex(move); return(moveString.Length switch { 2 => sourceIndex == ChessConstants.Pawn && moveString.Substring(0, 1).Equals(bestMove.ToFile + "") && moveString.Substring(1, 1).Equals(bestMove.ToRank + ""), 3 when moveString.Substring(0, 1).ToLower().Equals(moveString.Substring(0, 1)) => sourceIndex == ChessConstants.Pawn && moveString.Substring(0, 1).Equals(bestMove.FromFile + "") && moveString.Substring(1, 1).Equals(bestMove.ToFile + "") && moveString.Substring(2, 1).Equals(bestMove.ToRank + ""), 3 => moveString.Substring(0, 1).Equals(ChessConstants.FenWhitePieces[sourceIndex]) && moveString.Substring(1, 1).Equals(bestMove.ToFile + "") && moveString.Substring(2, 1).Equals(bestMove.ToRank + ""), 4 => moveString.Substring(0, 1).Equals(ChessConstants.FenWhitePieces[sourceIndex]) && moveString.Substring(1, 1).Equals(bestMove.FromFile + "") && moveString.Substring(2, 1).Equals(bestMove.ToFile + "") && moveString.Substring(3, 1).Equals(bestMove.ToRank + ""), _ => throw new ArgumentException("Unknown move string: " + moveString) });
public String MoveWrapperToString(MoveWrapper mw) { if (mw.HasUsedCell()) return String.Format("MOVE: Type {0}, FTU: {1},{2},{3}", mw.GetMoveType(), mw.GetFromCell(), mw.GetToCell(), mw.GetUsedCell()); return String.Format("MOVE: Type {0}, FTU: {1},{2}, None", mw.GetMoveType(), mw.GetFromCell(), mw.GetToCell()); }
public Turn ConvertMoveToTurn(MoveWrapper mw) { CommunicationProtocol.MoveType mt = CommunicationProtocol.MoveType.Insert; switch (mw.GetMoveType()) { case engine.wrapper.MoveType.INSERT: mt = CommunicationProtocol.MoveType.Insert; break; case engine.wrapper.MoveType.JUMP: mt = CommunicationProtocol.MoveType.Jump; break; case engine.wrapper.MoveType.STEP: mt = CommunicationProtocol.MoveType.Move; break; } Turn t = new Turn(); t.MoveType = mt; if (mw.HasUsedCell()) { t.EmptyTile = ConvertBoardPositionToInt(mw.GetUsedCell()); } else { t.EmptyTile = null; } if (mw.GetMoveType() == engine.wrapper.MoveType.INSERT) { t.FromTile = ConvertBoardPositionToInt(mw.GetToCell()); t.Direction = Direction.None; } else { t.FromTile = ConvertBoardPositionToInt(mw.GetFromCell()); t.Direction = CalculateDirection(mw.GetToCell(), mw.GetFromCell()); } return t; }
private void OnMoveExecuted(MoveWrapper move) { if (move.GetMoveType() == MoveType.INSERT) { _lastMoveHighlight[0] = move.GetToCell(); } else { _lastMoveHighlight[0] = move.GetFromCell(); _lastMoveHighlight[1] = move.GetToCell(); // Adjust coordinates if board moved around. if (_lastMoveHighlight[1].X < 0) { _lastMoveHighlight[0].X++; _lastMoveHighlight[1].X++; } if (_lastMoveHighlight[1].Y < 0) { _lastMoveHighlight[0].Y++; _lastMoveHighlight[1].Y++; } if (move.HasUsedCell() && karoGame.KaroGameManager.Board.GetRelativeCellAt( move.GetUsedCell()).HasTile()) { if (move.GetUsedCell().X == 0 && move.GetToCell().X >= 0 && move.GetToCell().Y >= 0) { _lastMoveHighlight[0].X--; _lastMoveHighlight[1].X--; } if (move.GetUsedCell().Y == 0 && move.GetToCell().X >= 0 && move.GetToCell().Y >= 0) { _lastMoveHighlight[0].Y--; _lastMoveHighlight[1].Y--; } } } if (_highlightThread.IsAlive) { _showHighlight = false; _highlightThread.Join(); } _highlightThread = new Thread(RemoveHighlightAfterOneSecond); _highlightThread.Start(); }
public bool MoveEquals(MoveWrapper bestMove) { return(_moveStrings.Any(moveString => MoveEquals(moveString, bestMove))); }
bool IsMoveLegal(MoveWrapper mv, Players player) { if (mv.GetMoveType() == engine.wrapper.MoveType.INSERT) { return FindLegalMoves(player). Any(m => m.GetToCell() == mv.GetToCell()); } return FindLegalMoves(player).Any(m => m.GetFromCell() == mv.GetFromCell() && m.GetToCell() == mv.GetToCell() && (!m.HasUsedCell() || m.GetUsedCell() == mv.GetUsedCell())); }
public virtual void ExecuteMove(MoveWrapper move) { MoveLog.Add(new KeyValuePair<MoveWrapper,Players>(move, CurrentPlayer)); Debug.WriteLine("TopLeft: {0}", Board.GetRelativeCellAt(new Vector2DWrapper(0, 0)).GetAbsolutePosition()); Debug.WriteLine("Before Execute Board State: {0}", Board.ToString()); Game.ExecuteMove(move, CurrentPlayer); _lastMove = move; Debug.WriteLine("After Board State: {0}", Board.ToString()); if (OnMoveExecuted != null) { OnMoveExecuted(move); } if (Game.HasWon(CurrentPlayer) && OnPlayerWin != null) { OnPlayerWin(CurrentPlayer); } if (OnBoardUpdated != null) { OnBoardUpdated(); } SwapCurrentPlayer(); }