public void MovePlannerInitializationCheck() { ChessBoard board = new ChessBoard(); MovePlanner planner = new MovePlanner(board); ChessPiece TestPiece = board.PieceAt(4, 1); Assert.AreEqual(TestPiece.Type, PieceType.Pawn); }
public void TestMoveComponentCompilation() { ChessLogic logic = new ChessLogic(); movePlanner = new MovePlanner(logic.Board); constructAnAxis(ref xMover, ref xCalibrator, ref xPreciseMover, ref xGridMover); constructAnAxis(ref yMover, ref yCalibrator, ref yPreciseMover, ref yGridMover); var magnet = new MockMagnet(); movePerformer = new MovePerformer(xGridMover, yGridMover, magnet); moveManager = new MoveManager(movePlanner, movePerformer); }
public static async Task <GameManager> CreateAsync() { var commandInterpreterConstructor = CommandInterpreter.CreateAsync(); ChessLogic logic = new ChessLogic(); var stepCountPinX = new GpioPinWrapper(5, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp); var stepClearPinX = new GpioPinWrapper(13, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low); var motorInformationX = new MotorInformation(Axis.X, stepCountPinX); var motorDriverX = new MotorDrv(20, 21, motorInformationX); var motorLocatorX = new MotorLocator(stepClearPinX, motorDriverX.Information); var positionSignalerX = new PositionSignaler(motorLocatorX); var motorMoverX = new MotorMover(50, positionSignalerX, motorLocatorX, motorDriverX); var stepCountPinY = new GpioPinWrapper(6, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp); var stepClearPinY = new GpioPinWrapper(19, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low); var motorInformationY = new MotorInformation(Axis.Y, stepCountPinY); var motorDriverY = new MotorDrv(24, 23, motorInformationY); var motorLocatorY = new MotorLocator(stepClearPinY, motorDriverY.Information); var positionSignalerY = new PositionSignaler(motorLocatorY); var motorMoverY = new MotorMover(50, positionSignalerY, motorLocatorY, motorDriverY); var topInterrupterX = new PhotoInterrupter(17, 1, 150); var bottomInterrupterX = new PhotoInterrupter(27, -1, -150); var motorCalibratorX = new MotorCalibrator(-23, 23, motorMoverX, motorInformationX, topInterrupterX, bottomInterrupterX); var topInterrupterY = new PhotoInterrupter(25, 1, 150); var bottomInterrupterY = new PhotoInterrupter(22, -1, -150); var motorCalibratorY = new MotorCalibrator(-17, 17, motorMoverY, motorInformationY, topInterrupterY, bottomInterrupterY); var preciseMoverX = new PreciseMotorMover(motorMoverX); var gridMoverX = new GridMotorMover(preciseMoverX, motorCalibratorX); var preciseMoverY = new PreciseMotorMover(motorMoverY); var gridMoverY = new GridMotorMover(preciseMoverY, motorCalibratorY); var magnetDriver = new MagnetDrv(26); var movePerformer = new MovePerformer(gridMoverX, gridMoverY, magnetDriver); var motorCalibrationTask = movePerformer.CalibrateAsync(); var movePlanner = new MovePlanner(logic.Board); var moveManager = new MoveManager(movePlanner, movePerformer); GameManager manager = new GameManager(await commandInterpreterConstructor, logic, moveManager); await motorCalibrationTask; #if DEBUG manager.DebugMovePerformer = movePerformer; #endif return(manager); }
public void SelectPlayer() { //Debug.Log("Player Selected!"); if (!Mission.Instance.SelectedPlayer) { _isSelected = true; Mission.Instance.SelectedPlayer = this; } else { Mission.Instance.SelectedPlayer.DeselectPlayer(); Mission.Instance.SelectedPlayer = this; _isSelected = true; } MovePlanner.OnSelectPlayer(); OnPlayerSelection?.Invoke(); }
public void SampleMoveCheckingPawnMoving() { //String correctPoints = "start move\n[12, 3]\n[12, 7]\nend move \n"; //Set moves //White King Pawn to E5 Point2D moveW1Start = new Point2D(4, 1); //start location of the first white move (0-7, 0-7) Point2D moveW1End = new Point2D(4, 3); List <IList <Point2D> > paths = new List <IList <Point2D> >(); //String printString = ""; ChessBoard board = new ChessBoard(); MovePlanner planner = new MovePlanner(board); paths = planner.PlanMove(moveW1Start, moveW1End); board.MovePiece(new Position(moveW1Start), new Position(moveW1End)); //System.Diagnostics.Debug.Write(printString); Assert.AreEqual("[1, -5]", paths[0][0].ToString()); Assert.AreEqual("[1, -1]", paths[0][1].ToString()); //Assert.AreEqual(correctPoints, printString); }
public void CapturingMovementTest() //tests move taking by enacting an impossible pawn zoom { //White King Pawn to E2 (magic!) Point2D moveW1Start = new Point2D(4, 1); //start location of the first white move (0-7, 0-7) Point2D moveW1End = new Point2D(4, 6); List <IList <Point2D> > paths = new List <IList <Point2D> >(); ChessBoard board = new ChessBoard(); MovePlanner planner = new MovePlanner(board); System.Diagnostics.Debug.WriteLine("about to get path"); paths = planner.PlanMove(moveW1Start, moveW1End); //board.MovePiece(new Position(moveW1Start), new Position(moveW1End)); Assert.AreEqual("[1, 5]", paths[0][0].ToString()); Assert.AreEqual("[1, 6]", paths[0][1].ToString()); Assert.AreEqual("[-9, 6]", paths[0][2].ToString()); Assert.AreEqual("[-9, 7]", paths[0][3].ToString()); Assert.AreEqual("[-11, 7]", paths[0][4].ToString()); Assert.AreEqual("[1, -5]", paths[1][0].ToString()); Assert.AreEqual("[1, 5]", paths[1][1].ToString()); }
public async Task VisualizerTest1() { ChessLogic logic = new ChessLogic(); MovePlanner planner = new MovePlanner(logic.Board); MovePerformerVisualizer visualizer = new MovePerformerVisualizer(); MoveManager manager = new MoveManager(planner, visualizer); visualizer.ResetBoardRep(); visualizer.PrintBoardRep(); List <Position[]> moves = new List <Position[]>(); Position[] move = new Position[2]; //can't reuse move like that, apparently move[0] = new Position("E", "2"); move[1] = new Position("E", "4"); moves.Add(move); foreach (var movement in moves) { logic.IsMoveValid(movement[0], movement[1]); await manager.MoveAsync(movement[0], movement[1]); logic.MovePiece(movement[0], movement[1]); } }
public async Task VisualizerTest3BasicUndo() { ChessLogic logic = new ChessLogic(); MovePlanner planner = new MovePlanner(logic.Board); MovePerformerVisualizer visualizer = new MovePerformerVisualizer(); MoveManager manager = new MoveManager(planner, visualizer); visualizer.ResetBoardRep(); visualizer.PrintBoardRep(); List <Position[]> moves = new List <Position[]>(); Position[] move1 = new Position[2]; move1[0] = new Position("E", "2"); move1[1] = new Position("E", "4"); moves.Add(move1); Position[] move2 = new Position[2]; move2[0] = new Position("D", "7"); move2[1] = new Position("D", "5"); moves.Add(move2); Position[] move3 = new Position[2]; move3[0] = new Position("G", "1"); move3[1] = new Position("F", "3"); moves.Add(move3); Position[] move4 = new Position[2]; move4[0] = new Position("C", "8"); move4[1] = new Position("E", "6"); moves.Add(move4); Position[] move5 = new Position[2]; move5[0] = new Position("F", "1"); move5[1] = new Position("C", "4"); moves.Add(move5); Position[] move6 = new Position[2]; move6[0] = new Position("B", "8"); move6[1] = new Position("C", "6"); moves.Add(move6); Position[] move7 = new Position[2]; move7[0] = new Position("E", "1"); move7[1] = new Position("E", "2"); moves.Add(move7); Position[] move8 = new Position[2]; move8[0] = new Position("D", "5"); move8[1] = new Position("E", "4"); moves.Add(move8); Position[] move9 = new Position[2]; move9[0] = new Position("C", "4"); move9[1] = new Position("E", "6"); moves.Add(move9); Position[] move10 = new Position[2]; move10[0] = new Position("E", "4"); move10[1] = new Position("F", "3"); moves.Add(move10); Position[] move11 = new Position[2]; move11[0] = new Position("A", "2"); move11[1] = new Position("A", "3"); moves.Add(move11); Position[] move12 = new Position[2]; move12[0] = new Position("F", "7"); move12[1] = new Position("E", "6"); moves.Add(move12); Position[] move13 = new Position[2]; move13[0] = new Position("E", "2"); move13[1] = new Position("F", "3"); moves.Add(move13); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); foreach (var movement in moves) { System.Diagnostics.Debug.WriteLine(movement[0].ToString() + "\t" + movement[1].ToString()); Assert.AreEqual(logic.IsMoveValid(movement[0], movement[1]), true); await manager.MoveAsync(movement[0], movement[1]); logic.MovePiece(movement[0], movement[1]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); } System.Diagnostics.Debug.WriteLine("Black castles kingside."); var rookLocationForBlackCastle = logic.validRookLocationsForCastling(); Assert.AreEqual(rookLocationForBlackCastle.Count, 1); await manager.CastleAsync(rookLocationForBlackCastle[0], logic.Board.GetKingCol()); logic.Castle(rookLocationForBlackCastle[0]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); System.Diagnostics.Debug.WriteLine("White castles queenside."); var rookLocationForWhiteCastle = logic.validRookLocationsForCastling(); Assert.AreEqual(rookLocationForWhiteCastle.Count, 1); await manager.CastleAsync(rookLocationForWhiteCastle[0], logic.Board.GetKingCol()); logic.Castle(rookLocationForWhiteCastle[0]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); for (int i = 0; i < moves.Count + 2; i++) //+2 for the two castles { await manager.UndoMoveAsync(); logic.UndoMove(); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); } }
public IEnumerator Plan_Coroutine(Unit requester, Action <List <APActionNode> > OnPlanCompleted) { APGameState initialGameState = APGameState.Create(requester, TurnMgr.Instance.turns.ToList(), MapMgr.Instance.map.Cubes.ToList()); List <APActionNode> leafNodes = new List <APActionNode>(); // BFS Tree Construction Queue <APActionNode> queue = new Queue <APActionNode>(); queue.Enqueue(new RootNode(initialGameState)); while (queue.Count > 0) { APActionNode parentNode = queue.Dequeue(); int childCount = 0; //************** MOVE NODES **************// MovePlanner movePlanner = new MovePlanner(parentNode._gameState, parentNode._score, actionPointPanel); if (movePlanner.IsAvailable(parentNode)) { // 시뮬레이션 List <APActionNode> moveNodes; bool simulCompleted = false; movePlanner.Simulate(this, () => simulCompleted = true, out moveNodes); // // // // // // // // // // // // // // // // // // // // // // // // while (!simulCompleted) { yield return(null); } // // // // // // // // // // // // // // // // // // // // // // // // // 부모노드 세팅 및 인큐 foreach (var node in moveNodes) { node._parent = parentNode; childCount++; queue.Enqueue(node); } } //************** ATTACK NODES **************// AttackPlanner attackPlanner = new AttackPlanner(parentNode._gameState, parentNode._score, actionPointPanel); if (attackPlanner.IsAvailable(parentNode)) { // 시뮬레이션 List <APActionNode> attackNodes; bool simulCompleted = false; attackPlanner.Simulate(this, () => simulCompleted = true, out attackNodes); // // // // // // // // // // // // // // // // // // // // // // // // while (!simulCompleted) { yield return(null); } // // // // // // // // // // // // // // // // // // // // // // // // // 부모노드 세팅 및 인큐 foreach (var node in attackNodes) { node._parent = parentNode; childCount++; queue.Enqueue(node); } } //************** ITEM NODES **************// //************** SKILL NODES **************// //*** Leaf Check ***// if (childCount == 0) { leafNodes.Add(parentNode); } yield return(null); } //*** 마지막 위치에 따른 점수 계산 ***// //*** Construct Best Action List ***// List <APActionNode> bestSequence = new List <APActionNode>();; // 가장 높은 스코어 추출 int bestScore = leafNodes.Aggregate((acc, curr) => curr._score > acc._score ? curr : acc)._score; // high score leaf들을 추출 List <APActionNode> bestLeaves = leafNodes.FindAll(ln => ln._score == bestScore); // high score leaf들의 마지막 self 위치에 따른 점수변동 CalcFinalPositionScore(bestLeaves, initialGameState); // 점수 변동한 leaf들로 다시 순위매김 int secondBestScore = bestLeaves.Aggregate((acc, curr) => curr._score > acc._score ? curr : acc)._score; bestLeaves = bestLeaves.FindAll(ln => ln._score == secondBestScore); //// 추출한 leaf들중 랜덤하게 고르기위한 idx int randomIdx = UnityEngine.Random.Range(0, bestLeaves.Count); //// 결정한 시퀀스의 leaf노드 APActionNode bestLeaf = bestLeaves[randomIdx]; // 시퀀스 생성 perent를 따라올라감 APActionNode currNode = bestLeaf; while (currNode.GetType() != typeof(RootNode)) // 미자막 RootNode는 안넣을겁니다. { bestSequence.Add(currNode); currNode = currNode._parent; yield return(null); } // leaf - {} - {} - {} - {} // 를 // {} - {} - {} - {} - leaf // 순으로 뒤집기 bestSequence.Reverse(); OnPlanCompleted(bestSequence); }
public void SetPlanner(MovePlanner movePlanner) { planner = movePlanner; }