public static string[] ControlledMove(MoveReference reference, GVector3 value, float feedrate, float extraction) { return(new string[] { reference == MoveReference.Absolute? AsAbsolute(): AsRelative(), GCode3018Pro.ControlledMove(value, feedrate, extraction) }); }
public static string [] ControlledMove(MoveReference reference, GVector3 value) { return(new string[] { reference == MoveReference.Absolute? AsAbsolute(): AsRelative(), GCode3018Pro.ControlledMove(value) }); }
public void SetMoveType(int index) { if (index == 0) { m_moveType = MoveReference.Relative; } if (index == 1) { m_moveType = MoveReference.Absolute; } }
public override bool run() { // Initialize Expected Files and Ranks for every piece for (int p = 0; p < pieces.Length; p++) { pieces[p].ExpectedFile = pieces[p].getFile(); pieces[p].ExpectedRank = pieces[p].getRank(); } // List of all valid moves, populated as we go List<MoveReference> valid_moves = new List<MoveReference>(); // Populate valid_moves with board-legal moves foreach (Piece piece in pieces) { // Only find moves for my pieces if (piece.getOwner() == playerID()) { // Get all moves for this piece at its current location Coordinate here = new Coordinate(piece.ExpectedFile, piece.ExpectedRank); foreach (Coordinate destination in GetMovesFor((char)piece.getType(), here, this)) { MoveReference move = new MoveReference(piece, destination); if (IsValidMove(move)) { valid_moves.Add(move); } } } } // Order moves by Iterative-Deepening Depth-Limited MiniMax with a material advantage state // eval heuristic // Pick a random move and make that move if (valid_moves.Count > 0) { MoveReference action = valid_moves[generator.Next(valid_moves.Count - 1)]; Console.WriteLine("Random move chosen: src ({0}, {1}), dest ({2}, {3})", action.Piece.getFile(), action.Piece.getRank(), action.To.File, action.To.Rank); Console.WriteLine("Piece chosen: {0}", (char)action.Piece.getType()); PrintValidMoves(valid_moves, action); action.Piece.move(action.To.File, action.To.Rank, (int)'Q'); } // Print game info PrintBoard(); //GameInfo(); return true; }
public void SetAsRelative(bool isRelative) { m_moveReference = isRelative ? MoveReference.Relative : MoveReference.Absolute; }
public void AZ(float valueInMM) { m_moveReference = MoveReference.Absolute; Z(valueInMM); }
public void RZ(float valueInMM) { m_moveReference = MoveReference.Relative; Z(valueInMM); }
// Determines whether a move is valid given the current board state, looking at // whether it ends up on an ally piece and whether it ends with us in check. private bool IsValidMove(MoveReference move) { // Piece that is moving Piece piece = move.Piece; // Where the piece is coming from (so we can revert later) Coordinate origin = new Coordinate(piece.ExpectedFile, piece.ExpectedRank); // Where this piece is moving to Coordinate destination = move.To; // Find any pieces that might be where we're going Piece target_piece = GetPieceAt(destination); if (target_piece != null) { // First, make sure the piece at that destination isn't ours! if (target_piece.getOwner() == playerID()) { // If it's ours, we clearly cannot make this move return false; } // Temporarily update the board state to take this piece off the board target_piece.ExpectedRank = -1; target_piece.ExpectedFile = -1; } // We want to make sure making this move will not place us in check. To do that, // we're going to look outward from the King after making the move and see if // any enemy pieces are putting us in check. piece.ExpectedFile = destination.File; piece.ExpectedRank = destination.Rank; if (IsKingInCheck()) { Debug(String.Format("Pruned {0} ({1}, {2}) to ({3}, {4})", (char)piece.getType(), origin.File, origin.Rank, destination.File, destination.Rank)); // Revert the board back to its original state piece.ExpectedFile = origin.File; piece.ExpectedRank = origin.Rank; if (target_piece != null) { target_piece.ExpectedRank = destination.Rank; target_piece.ExpectedFile = destination.File; } // Don't make any moves that end with us in check return false; } // If the move doesn't leave us in check, it's a valid move. Reverting back to the // original board state before returning true. if (target_piece != null) { target_piece.ExpectedRank = destination.Rank; target_piece.ExpectedFile = destination.File; } // And finally, revert the moving piece back to its original state so we can properly // look at other moves piece.ExpectedFile = origin.File; piece.ExpectedRank = origin.Rank; // Great success! return true; }
private void PrintValidMoves(List<MoveReference> move_list, MoveReference chosen) { Console.Write("Other moves: "); for (int i = 0; i < move_list.Count; i++) { MoveReference mv = move_list[i]; // #todo don't use getId() lolol if (mv.Piece.getId() == chosen.Piece.getId()) { Console.Write("({1}, {2})", (char)mv.Piece.getType(), mv.To.File, mv.To.Rank); } } Console.WriteLine(); }