public ValidMoves(ValidMoves state) { up = state.up; down = state.down; left = state.left; right = state.right; }
internal async void OnBoardSquareTapped(object sender, PositionEventArgs e) { if (_model.GameInformation.NextToMove != _playerSide) { return; } var pieceAtSquare = _model.GetPieceAt(e.LogicalPosition); if (pieceAtSquare != null && pieceAtSquare.Side == _model.GameInformation.NextToMove) { SetSelection(pieceAtSquare, e.LogicalPosition); return; } if (_selectedPiece != null) { if (ValidMoves.Contains(e.LogicalPosition) || ValidAttacks.Contains(e.LogicalPosition)) { try { _model.ExecuteMove(await TurnFromPiecePositionChange(_selectedPiece, _selectedSquare.Value, e.LogicalPosition, true), true); SetVisiblePositionsForPlayer(); _board.IsSwitchPlayerEnabled = true; _board.IsGameBoardEnabled = false; SetSelection(null, null); } catch (OperationCanceledException) { // ignore touch return; } } } }
public virtual void RemoveDestination(Location destination) { foreach (var move in ValidMoves.Where(x => x.Destination == destination).ToList()) { ValidMoves.Remove(move); } }
private void getValidMoves() { ValidMoves.Clear(); Point start = new Point(); Size direction = new Size(); bool nextMove; for (start.X = 0; start.X < Board.GetLength(0); ++start.X) { for (start.Y = 0; start.Y < Board.GetLength(1); ++start.Y) { nextMove = (Board[start.X, start.Y] != GameState.player.NONE); for (direction.Width = -1; !nextMove && direction.Width < 2; ++direction.Width) { for (direction.Height = -1; !nextMove && direction.Height < 2; ++direction.Height) { if (direction != new Size(0, 0) && checkDirection(start, direction)) { ValidMoves.Add(start); nextMove = true; } } } } } }
public bool IsMoveValid(Move move, Playground playground) { if (!ValidMoves.Contains(move)) { return(false); } return(!playground.Rows.Where((s, i) => s < move.ChangesPerRow[i]).Any()); }
/* * Gets all valid move for the selected piece and updates the ViewModel */ private void ShowValidMoves(Square FromSquare) { //var color = Game.CurrentPlayer.Color == ChessColor.Black ? ChessColor.White : ChessColor.Black; var color = Game.CurrentPlayer.Color; ValidMoves.Clear(); GetAllValidMoves.AllValidMoves.Clear(); GetAllValidMoves.GetMoves(Game.ml, FromSquare, color, false); for (int i = 0; i < GetAllValidMoves.AllValidMoves.Count; i++) { ValidMoves.Add(ConvertCordToIndex(GetAllValidMoves.AllValidMoves[i])); ChessBoard[ValidMoves[i]].ValidMove = Visibility.Visible; } }
private void CheckAndInsertPawnForwards(int yOff, ChessBoard board) { var pos = new ChessPosition(CurrentPosition.X, (byte)(CurrentPosition.Y + (Owner == PlayerColor.White ? yOff : -yOff))); if (!ChessBoard.IsInBoard(pos)) { return; } var b = board[pos]; if (b != default) { return; } ValidMoves.Add(pos); }
// Save possible valid moves for the current player public void GetValidMoves(Player i_CurrentPlayer) { ValidMoves.Clear(); for (int i = 0; i < m_BoardGame.ScreenBoard.GetLength(0); i++) { for (int j = 0; j < m_BoardGame.ScreenBoard.GetLength(0); j++) { if (m_BoardGame.IsValidMove(i_CurrentPlayer, i, j)) { string RowToConcat = (i + 1).ToString(); string ColToConcat = ((char)(j + 'A')).ToString(); string ValidMoveToAdd = string.Concat(ColToConcat, RowToConcat); ValidMoves.Add(ValidMoveToAdd); } } } }
private void CheckAndInsertPawnDiagonal(int xOff, ChessBoard board) { var pos = new ChessPosition((byte)(CurrentPosition.X + xOff), (byte)(CurrentPosition.Y + (Owner == PlayerColor.White ? 1 : -1))); if (!ChessBoard.IsInBoard(pos)) { return; } var b = board[pos]; if (b == default) { return; } if (!b.Owner.Equals(Owner)) { ValidMoves.Add(pos); } }
protected bool CheckAndInsert(ChessPosition pos, ChessBoard board) { if (!ChessBoard.IsInBoard(pos)) { return(false); } // TODO: CheckmateCheck var b = board[pos]; if (b == default) { ValidMoves.Add(pos); return(true); } if (b.Owner == Owner) { return(false); } ValidMoves.Add(pos); return(false); }
public void RandomizeMoveTutorMoves(bool noBroken, bool preserveField, double goodDamagingProbability) { // Get current sets var hms = RomHandler.Machines .Where(machine => machine.Type == Machine.Kind.Hidden) .Select(machine => machine.Move).ToArray(); // Get current sets var tms = RomHandler.Machines .Where(machine => machine.Type == Machine.Kind.Technical) .Select(machine => machine.Move).ToArray(); // Pick some random Move Tutor moves, excluding TMs. var oldMTs = RomHandler.MoveTutorMoves; var mtCount = oldMTs.Length; var banned = new List <Move>(noBroken ? RomHandler.Moves.Where(move => Move.GameBreaking.Contains(move.Id)) : Enumerable.Empty <Move>()); // field moves? var fieldMoves = RomHandler.Moves.Where(move => RomHandler.Game.FieldMoves.Contains(move.Id)); var preservedFieldMoveCount = 0; if (preserveField) { var banExistingField = new List <Move>(oldMTs); banExistingField.RemoveAll(i => !fieldMoves.Contains(i)); preservedFieldMoveCount = banExistingField.Count; banned.AddRange(banExistingField); } // Determine which moves are pickable var usableMoves = ValidMoves.ToList(); usableMoves.RemoveAt(0); // remove null entry var unusableMoves = new HashSet <Move>(); var unusableDamagingMoves = new HashSet <Move>(); foreach (var mv in usableMoves) { if (GlobalConstants.BannedRandomMoves[mv.Id] || tms.Contains(mv) || hms.Contains(mv) || banned.Contains(mv)) { unusableMoves.Add(mv); } else if (GlobalConstants.BannedForDamagingMove[mv.Id] || mv.Power < GlobalConstants.MinDamagingMovePower) { unusableDamagingMoves.Add(mv); } } usableMoves.RemoveAll(unusableMoves.Contains); var usableDamagingMoves = new List <Move>(usableMoves); usableDamagingMoves.RemoveAll(unusableDamagingMoves.Contains); // pick (tmCount - preservedFieldMoveCount) moves var pickedMoves = new List <Move>(); for (var i = 0; i < mtCount - preservedFieldMoveCount; i++) { Move chosenMove; if (Random.NextDouble() < goodDamagingProbability && usableDamagingMoves.Count > 0) { chosenMove = usableDamagingMoves[Random.Next(usableDamagingMoves.Count)]; } else { chosenMove = usableMoves[Random.Next(usableMoves.Count)]; } pickedMoves.Add(chosenMove); usableMoves.Remove(chosenMove); usableDamagingMoves.Remove(chosenMove); } // shuffle the picked moves because high goodDamagingProbability // could bias them towards early numbers otherwise pickedMoves.Shuffle(Random); // finally, distribute them as tutors var pickedMoveIndex = 0; for (var i = 0; i < mtCount; i++) { if (preserveField && fieldMoves.Contains(oldMTs[i])) { continue; } oldMTs[i] = pickedMoves[pickedMoveIndex++]; } }
public static bool BackTrackRecursion()//This only returns true if we found the answer { PuzzleState state = stateDatabase[stateDatabase.Count - 1]; ValidMoves moves = CheckPossibleMoves(state.state); if (!state.moved.up && moves.up) { repetitions++; PuzzleState newState = MovePiece(state, 0); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { stateDatabase.Add(newState); return(true); } else if (CheckIfStateExists(newState))//need to check next possible move { state.moved.up = true; stateDatabase[stateDatabase.Count - 1] = state; } else { state.moved.up = true; stateDatabase[stateDatabase.Count - 1] = state; stateDatabase.Add(newState); return(false); } } if (!state.moved.left && moves.left) { repetitions++; PuzzleState newState = MovePiece(state, 2); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { stateDatabase.Add(newState); return(true); } else if (CheckIfStateExists(newState))//need to check next possible move { state.moved.left = true; stateDatabase[stateDatabase.Count - 1] = state; } else { state.moved.left = true; stateDatabase[stateDatabase.Count - 1] = state; stateDatabase.Add(newState); return(false); } } if (!state.moved.down && moves.down) { repetitions++; PuzzleState newState = MovePiece(state, 1); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { stateDatabase.Add(newState); return(true); } else if (CheckIfStateExists(newState))//need to check next possible move { state.moved.down = true; stateDatabase[stateDatabase.Count - 1] = state; } else { state.moved.down = true; stateDatabase[stateDatabase.Count - 1] = state; stateDatabase.Add(newState); return(false); } } if (!state.moved.right && moves.right) { repetitions++; PuzzleState newState = MovePiece(state, 3); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { stateDatabase.Add(newState); return(true); } else if (CheckIfStateExists(newState))//need to check next possible move { state.moved.right = true; stateDatabase[stateDatabase.Count - 1] = state; } else { state.moved.right = true; stateDatabase[stateDatabase.Count - 1] = state; stateDatabase.Add(newState); return(false); } } stateDatabase.RemoveAt(stateDatabase.Count - 1); return(false); }
public override bool ValidMovement(BoardLogic.ChessCoordinates startLocation, BoardLogic.ChessCoordinates endLocation) { //validate movement eventually ValidMoves.Clear(); int column = FileLogic.GetColumnFromChar(startLocation.Column).GetHashCode(); int row = startLocation.Row; if (Program.board[column, row].Piece.IsLight) { if (column - 1 >= 0) { if (Program.board[column - 1, row].Piece == null) { ValidMoves.Add(Program.board[column - 1, row]); if (column == 6) { if (Program.board[column - 2, row].Piece == null) { ValidMoves.Add(Program.board[column - 2, row]); } } } if (row - 1 >= 0 && Program.board[column - 1, row - 1].Piece != null && Program.board[column - 1, row - 1].Piece.IsLight != Program.board[column, row].Piece.IsLight) { ValidMoves.Add(Program.board[column - 1, row - 1]); } if (row + 1 <= 7 && Program.board[column - 1, row + 1].Piece != null && Program.board[column - 1, row + 1].Piece.IsLight != Program.board[column, row].Piece.IsLight) { ValidMoves.Add(Program.board[column - 1, row + 1]); } } } else if (!Program.board[column, row].Piece.IsLight) { if (column + 1 <= 7) { if (Program.board[column + 1, row].Piece == null) { ValidMoves.Add(Program.board[column + 1, row]); if (column == 1) { if (Program.board[column + 2, row].Piece == null) { ValidMoves.Add(Program.board[column + 2, row]); } } } if (row - 1 >= 0 && Program.board[column + 1, row - 1].Piece != null && Program.board[column + 1, row - 1].Piece.IsLight != Program.board[column, row].Piece.IsLight) { ValidMoves.Add(Program.board[column + 1, row - 1]); } if (row + 1 <= 7 && Program.board[column + 1, row + 1].Piece != null && Program.board[column + 1, row + 1].Piece.IsLight != Program.board[column, row].Piece.IsLight) { ValidMoves.Add(Program.board[column + 1, row + 1]); } } } BoardLogic.ChessCoordinates lookingFor = new BoardLogic.ChessCoordinates(BoardLogic.GetCharFromNumber(FileLogic.GetColumnFromChar(endLocation.Column).GetHashCode()), endLocation.Row, null); //BoardLogic.ChessCoordinates lookingFor2 = new BoardLogic.ChessCoordinates(BoardLogic.GetCharFromNumber(endLocation.Row), FileLogic.GetColumnFromChar(endLocation.Column).GetHashCode(), null); foreach (var space in ValidMoves) { if (space == lookingFor) { return(true); } } return(false); }
public PuzzleState(List <List <int> > list, ValidMoves last) { state = new List <List <int> >(list); moved = last; this.path = new List <int>(); }
public virtual void AddMoves(List <IPlayerMove> newMoves) { newMoves.ToList().ForEach(x => ValidMoves.Add(x)); }
public List <Move> GetValidMoves(Playground playground) { return(ValidMoves.Where(m => IsMoveValid(m, playground)).ToList()); }
public static PuzzleState GraphSearchRecursion() { while (true) { int count = queue.Count; for (int i = 0; i < count; i++) { PuzzleState state = queue[i]; ValidMoves moves = CheckPossibleMoves(state.state); if (state.path[state.path.Count - 1] != 1 && moves.up) { repetitions++; PuzzleState newState = MovePiece(state, 0); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { newState.path.Add(0); return(newState);//found the answer } else {//update and add to queue newState.path.Add(0); queueTemp.Add(newState); } } if (state.path[state.path.Count - 1] != 3 && moves.left) { repetitions++; PuzzleState newState = MovePiece(state, 2); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { newState.path.Add(2); return(newState);//found the answer } else {//update and add to queue newState.path.Add(2); queueTemp.Add(newState); } } if (state.path[state.path.Count - 1] != 0 && moves.down) { repetitions++; PuzzleState newState = MovePiece(state, 1); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { newState.path.Add(1); return(newState);//found the answer } else {//update and add to queue newState.path.Add(1); queueTemp.Add(newState); } } if (state.path[state.path.Count - 1] != 2 && moves.right) { repetitions++; PuzzleState newState = MovePiece(state, 3); if (CheckTwoStates(newState.state, target.goal, state.state.Count)) { newState.path.Add(3); return(newState);//found the answer } else {//update and add to queue newState.path.Add(3); queueTemp.Add(newState); } } } queue.Clear(); queue = new List <PuzzleState>(queueTemp); queueTemp.Clear(); } }
private static ValidMoves CheckValidMoves(LineGrid grid, Tuple <int, int> currentPosition, char currentPosChar, Dictionary <Tuple <int, int>, int> positionDict, ValidMoves lastMove) { var dir = new Direction(grid, currentPosition); switch (currentPosChar) { case '-': dir.IsLeft = !OnList(positionDict, currentPosition, 0, -1) && new char[] { '+', '-', 'X' }.Contains(dir.LeftChar); dir.IsRight = !OnList(positionDict, currentPosition, 0, 1) && new char[] { '+', '-', 'X' }.Contains(dir.RightChar); return(dir.GetMove()); case '|': dir.IsUp = !OnList(positionDict, currentPosition, -1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.UpChar); dir.IsDown = !OnList(positionDict, currentPosition, 1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.DownChar); return(dir.GetMove()); case '+': dir.IsUp = (!OnList(positionDict, currentPosition, -1, 0)) && (lastMove != ValidMoves.Down && lastMove != ValidMoves.Up && new char[] { '+', '|', 'X' }.Contains(dir.UpChar)); dir.IsDown = (!OnList(positionDict, currentPosition, 1, 0)) && (lastMove != ValidMoves.Down && lastMove != ValidMoves.Up && new char[] { '+', '|', 'X' }.Contains(dir.DownChar)); dir.IsLeft = !OnList(positionDict, currentPosition, 0, -1) && (lastMove != ValidMoves.Left && lastMove != ValidMoves.Right && new char[] { '+', '-', 'X' }.Contains(dir.LeftChar)); dir.IsRight = !OnList(positionDict, currentPosition, 0, 1) && (lastMove != ValidMoves.Left && lastMove != ValidMoves.Right && new char[] { '+', '-', 'X' }.Contains(dir.RightChar)); return(dir.GetMove()); case 'X': dir.IsUp = !OnList(positionDict, currentPosition, -1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.UpChar); dir.IsDown = !OnList(positionDict, currentPosition, 1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.DownChar); dir.IsLeft = !OnList(positionDict, currentPosition, 0, -1) && new char[] { '+', '-', 'X' }.Contains(dir.LeftChar); dir.IsRight = !OnList(positionDict, currentPosition, 0, 1) && new char[] { '+', '-', 'X' }.Contains(dir.RightChar); return(dir.GetMove()); default: throw new ArgumentException($"Invalid Current Position Character - '{currentPosChar}'", nameof(currentPosChar)); } }
public bool CanPlayMove(Move move) { return(GameInProgress && CurrentTurnIsHuman && null != move && null != ValidMoves && ValidMoves.Contains(move)); }
public MoveOutput Find(Cell dst) => ValidMoves.FirstOrDefault(x => x.Cell.ToString() == dst.ToString());
public void RandomizeTmMoves( bool noBroken, bool preserveField, bool levelupTmMoveSanity, double goodDamagingProbability) { // Get current sets var hms = RomHandler.Machines .Where(machine => machine.Type == Machine.Kind.Hidden) .Select(machine => machine.Move).ToArray(); // Get current sets var tms = RomHandler.Machines .Where(machine => machine.Type == Machine.Kind.Technical) .Select(machine => machine.Move).ToArray(); var banned = new List <Move>(noBroken ? RomHandler.Moves.Where(move => Move.GameBreaking.Contains(move.Id)) : Enumerable.Empty <Move>()); // field moves? var fieldMoves = RomHandler.Moves.Where(move => RomHandler.Game.FieldMoves.Contains(move.Id)); var preservedFieldMoveCount = 0; if (preserveField) { var banExistingField = new List <Move>(tms); banExistingField.RemoveAll(i => !fieldMoves.Contains(i)); preservedFieldMoveCount = banExistingField.Count; banned.AddRange(banExistingField); } // Determine which moves are pickable var usableMoves = ValidMoves.ToList(); usableMoves.RemoveAt(0); // remove null entry var unusableMoves = new HashSet <Move>(); var unusableDamagingMoves = new HashSet <Move>(); foreach (var mv in usableMoves) { if (GlobalConstants.BannedRandomMoves[mv.Id] || hms.Contains(mv) || banned.Contains(mv)) { unusableMoves.Add(mv); } else if (GlobalConstants.BannedForDamagingMove[mv.Id] || mv.Power < GlobalConstants.MinDamagingMovePower) { unusableDamagingMoves.Add(mv); } } usableMoves.RemoveAll(unusableMoves); var usableDamagingMoves = new List <Move>(usableMoves); usableDamagingMoves.RemoveAll(unusableDamagingMoves.Contains); // pick (tmCount - preservedFieldMoveCount) moves var pickedMoves = new List <Move>(); for (var i = 0; i < RomHandler.Machines.Count - preservedFieldMoveCount; i++) { Move chosenMove; if (Random.NextDouble() < goodDamagingProbability && usableDamagingMoves.Count > 0) { chosenMove = usableDamagingMoves[Random.Next(usableDamagingMoves.Count)]; } else { chosenMove = usableMoves[Random.Next(usableMoves.Count)]; } pickedMoves.Add(chosenMove); usableMoves.Remove(chosenMove); usableDamagingMoves.Remove(chosenMove); } // shuffle the picked moves because high goodDamagingProbability // could bias them towards early numbers otherwise pickedMoves.Shuffle(Random); // finally, distribute them as tms var pickedMoveIndex = 0; for (var i = 0; i < RomHandler.Machines.Count; i++) { if (preserveField && fieldMoves.Contains(tms[i])) { continue; } RomHandler.Machines[i].Move = pickedMoves[pickedMoveIndex++]; } if (!levelupTmMoveSanity) { return; } // if a pokemon learns a move in its moveset // and there is a TM of that move, make sure // that TM can be learned. var movesFromMachines = new HashSet <Move>(RomHandler.Machines.Select(m => m.Move)); foreach (var pokemon in ValidPokemons) { var moveset = pokemon.MovesLearnt; var pkmnCompat = pokemon.TMHMCompatibility; foreach (var ml in moveset) { if (!movesFromMachines.Contains(ml.Move)) { continue; } var learnt = pkmnCompat.First(machineL => machineL.Machine.Move == ml.Move); learnt.Learns = true; } } }