Ejemplo n.º 1
0
 public static bool ChangePawnToDame(FieldState[,] boardArray)
 {
     for (var i = 0; i < 8; i++)
         if (boardArray[0, i] == FieldState.YellowPawn || boardArray[7, i] == FieldState.RedPawn)
             return true;
     return false;
 }
 private void AddFields(List<CustomFieldObject> FieldList, int NumberOfFields, FieldState fieldState)
 {
     for (int i = 0; i < NumberOfFields; i++)
     {
         FieldList.Add(CreateField(fieldState));
     }
 }
Ejemplo n.º 3
0
 public Pawn(int x, int y, FieldState currentState, FieldState previousState)
 {
     X = x;
     Y = y;
     CurrentState = currentState;
     PreviousState = previousState;
 }
Ejemplo n.º 4
0
 private FieldState[,] boardArrayToFieldState()
 {
     var result = new FieldState[8, 8];
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             switch (_boardArray[i, j])
             {
                 case 0:
                     result[i, j] = FieldState.Empty;
                     break;
                 case 1:
                     result[i, j] = FieldState.RedPawn;
                     break;
                 case 2:
                     result[i, j] = FieldState.YellowPawn;
                     break;
                 case 3:
                     result[i, j] = FieldState.BluePawn;
                     break;
                 case 4:
                     result[i, j] = FieldState.GreenPawn;
                     break;
                 default:
                     result[i, j] = FieldState.Empty;
                     break;
             }
         }
     }
     return result;
 }
Ejemplo n.º 5
0
 private static void MoveDames(int x, int y, FieldState fieldState, GameState gameState)
 {
     if (fieldState != gameState.CurrentDame) return;
     for (var i = 0; i < 8; i++) MovePawn(x, y, x + i, y + i, gameState);
     for (var i = 0; i < 8; i++) MovePawn(x, y, x + i, y - i, gameState);
     for (var i = 0; i < 8; i++) MovePawn(x, y, x - i, y - i, gameState);
     for (var i = 0; i < 8; i++) MovePawn(x, y, x - i, y + i, gameState);
 }
Ejemplo n.º 6
0
 public static bool ChangedPawns(FieldState[,] boardArray, FieldState[,] previousBoardArray)
 {
     for (var i = 0; i < 8; i++)
         if ((previousBoardArray[7, i] == FieldState.RedPawn && boardArray[7, i] != FieldState.BluePawn) ||
             (previousBoardArray[0, i] == FieldState.YellowPawn && boardArray[0, i] != FieldState.GreenPawn))
                 return false;
     return true;
 }
Ejemplo n.º 7
0
 private static void CapturePawns(FieldState[,] boardState, int x, int y, GameState gameState)
 {
     if (boardState[x, y] != gameState.CurrentPawn) return;
     CapturePawn(boardState, x, y, 1, 1, gameState, gameState.CurrentPawn);
     CapturePawn(boardState, x, y, 1, -1, gameState, gameState.CurrentPawn);
     CapturePawn(boardState, x, y, -1, -1, gameState, gameState.CurrentPawn);
     CapturePawn(boardState, x, y, -1, 1, gameState, gameState.CurrentPawn);
 }
Ejemplo n.º 8
0
 private static void CaptureDames(FieldState[,] boardState, int x, int y, GameState gameState)
 {
     if (boardState[x, y] != gameState.CurrentDame) return;
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, i, i, gameState, gameState.CurrentDame);
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, i, -i, gameState, gameState.CurrentDame);
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, -i, -i, gameState, gameState.CurrentDame);
     for (var i = 0; i < 8; i++) CapturePawn(boardState, x, y, -i, i, gameState, gameState.CurrentDame);
 }
Ejemplo n.º 9
0
        public override Point OnMove(FieldState[,] board)
        {
            var tocka = Helpers.RandomPoint(Height, Width);

            while (!board[(int)tocka.Y, (int)tocka.X].HasFlag(FieldState.Unknown))
                tocka = Helpers.RandomPoint(Height, Width);

            return tocka;
        }
Ejemplo n.º 10
0
 public static void ShowNotEmptyBoardContent(FieldState[,] board)
 {
     for(var i=0; i<8; i++)
         for (var j = 0; j < 8; j++)
         {
             if (board[i, j] == FieldState.Empty) continue;
             Console.WriteLine("[{0}, {1}] = {2}", i, j, board[i,j]);
         }
 }
Ejemplo n.º 11
0
 private static void MovePawns(int x, int y, FieldState fieldState, GameState gameState)
 {
     if (fieldState != gameState.CurrentPawn) return;
     var direction = 0;
     if (fieldState == FieldState.RedPawn) direction = 1;
     if (fieldState == FieldState.YellowPawn) direction = -1;
     MovePawn(x, y, x + direction, y + 1, gameState);
     MovePawn(x, y, x + direction, y - 1, gameState);
 }
Ejemplo n.º 12
0
 public GameState(FieldState[,] boardArray)
 {
     BoardArray = boardArray;
     PossibleMoves = new List<FieldState[,]>();
     PossibleCapture = new List<FieldState[,]>();
     CurrentPlayer = 0;
     CurrentPawn = FieldState.RedPawn;
     CurrentDame = FieldState.BluePawn;
 }
Ejemplo n.º 13
0
 public GameState()
 {
     BoardArray = new FieldState[8, 8];
     PreviousBoardArray = new FieldState[8, 8];
     PossibleMoves = new List<FieldState[,]>();
     PossibleCapture = new List<FieldState[,]>();
     CurrentPlayer = 0;
     CurrentPawn = FieldState.RedPawn;
     CurrentDame = FieldState.BluePawn;
 }
Ejemplo n.º 14
0
 public Field(int mineFieldCoordsX, int minefieldCoordsY, Vector2 displayPos, ref Field[,] map)
 {
     this.pos = displayPos;
     this.mineFieldCoordsX = mineFieldCoordsX;
     this.mineFieldCoordsY = minefieldCoordsY;
     this.fsFieldState = FieldState.unrevealed;
     this.map = map;
     this.texture = manager.contentManager.fieldTexUnrevealed;
     this.font = manager.contentManager.fntMinesNerby;
     this.rect = new Rectangle((int)pos.X, (int)pos.Y, 16, 16);
 }
Ejemplo n.º 15
0
 public Playground(int width, int height, int depth, FieldState initial = FieldState.Empty)
 {
     Width = width;
     Height = height;
     Depth = depth;
     Field = new FieldState[width, height, depth];
     for (int x = 0; x < Width; x++)
         for (int y = 0; y < Height; y++)
             for (int z = 0; z < Depth; z++)
                 Field[x, y, z] = initial;
 }
Ejemplo n.º 16
0
        public static void SetPossibleCapture(FieldState[,] boardState, GameState gameState)
        {
            gameState.PossibleCapture.Clear();

            for (var i = 0; i < 8; i++)
                for (var j = 0; j < 8; j++)
                {
                    CapturePawns(boardState, i, j, gameState);
                    CaptureDames(boardState, i, j, gameState);
                }
        }
Ejemplo n.º 17
0
        public List<Pawn> GetDiff(FieldState[,] baseArray = null, FieldState[,] compareArray = null)
        {
            if (baseArray == null) baseArray = _gameState.BoardArray;
            if (compareArray == null) compareArray = _gameState.PreviousBoardArray;
            var result = new List<Pawn>();

            for(var i=0; i<8; i++)
                for (var j = 0; j < 8; j++)
                    if (baseArray[i, j] != compareArray[i, j])
                        result.Add(new Pawn(i, j, baseArray[i, j], compareArray[i, j]));
            return result;
        }
Ejemplo n.º 18
0
 public void UpdateBoard(FieldState[,] boardArray)
 {
     _gameState.BoardArray = boardArray;
     CaptureHelper.SetPossibleCapture(_gameState.PreviousBoardArray, _gameState);
     MoveHelper.SetPossibleMoves(_gameState);
     Validete();
     if (MoveHelper.ChangePawnToDame(_gameState.BoardArray)) return;
     if (_playerCapture)
     {
         CaptureHelper.SetPossibleCapture(_gameState.BoardArray, _gameState);
         if (_gameState.PossibleCapture.Any()) return;
     }
     if (!IsError)
         _gameState.UpdateCurrentPlayer();
     Console.WriteLine("Current player: {0}", _gameState.CurrentPlayer + 1);
 }
Ejemplo n.º 19
0
        public string UpdateAndValidBoard(FieldState[,] boardArray)
        {
            if (!BoardIsNew(boardArray))
                return String.Empty;

            if (IsError && GetDiff(boardArray, _gameState.PreviousBoardArray).Count == 0)
            {
                IsError = false;
                _gameState.Restore();
                return "Now is OK";
            }

            if (!IsError)
                UpdateBoard(boardArray);

            return Message;
        }
Ejemplo n.º 20
0
        private static void CapturePawn(FieldState[,] boardState, int currentX, int currentY, int moveX, int moveY, GameState gameState, FieldState currentPawnType)
        {
            var opponentPawnX = currentX + moveX;
            var opponentPawnY = currentY + moveY;
            var opponentPawn = gameState.CurrentPawn == FieldState.RedPawn ? FieldState.YellowPawn : FieldState.RedPawn;
            var opponentDame = gameState.CurrentDame == FieldState.BluePawn ? FieldState.GreenPawn : FieldState.BluePawn;
            var newX = currentX + (moveX > 0 ? moveX + 1 : moveX - 1);
            var newY = currentY + (moveY > 0 ? moveY + 1 : moveY - 1);

            if ((boardState[currentX, currentY] != currentPawnType) ||
                (opponentPawnX < 0 || opponentPawnX > 7 || opponentPawnY < 0 || opponentPawnY > 7) ||
                (newX < 0 || newX > 7 || newY < 0 || newY > 7) ||
                !((boardState[opponentPawnX, opponentPawnY] == opponentPawn) || (boardState[opponentPawnX, opponentPawnY] == opponentDame)) ||
                (boardState[newX, newY] != FieldState.Empty))
                return;

            var tmpBoard = (FieldState[,])boardState.Clone();
            tmpBoard[newX, newY] = tmpBoard[currentX, currentY];
            tmpBoard[currentX, currentY] = FieldState.Empty;
            tmpBoard[opponentPawnX, opponentPawnY] = FieldState.Empty;
            gameState.PossibleCapture.Add(tmpBoard);
        }
Ejemplo n.º 21
0
 public GameField(FieldState state)
 {
     this.State = state;
 }
Ejemplo n.º 22
0
 private void Initialize(FieldState initialState)
 {
     _width            = initialState.Width;
     _height           = initialState.Height;
     _cellGroupManager = new CellGroupManager(initialState);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// public Constructor
 /// </summary>
 public GameBoard()
 {
     BoardDataDisplay = new FieldState[BoardConsts.BoardHeight * BoardConsts.BoardWidth];
     BoardDataBuffer  = new FieldState[(BoardConsts.BoardHeight + BoardConsts.BoardHeightOffset) * BoardConsts.BoardWidth];
     currentBrick     = new Brick();
 }
Ejemplo n.º 24
0
 public Player(FieldState mark, string ID)
 {
     this.ID   = ID;
     this.Mark = mark;
 }
 void ChangeAddressFieldEvent(string text, string example_text, FieldState state)
 {
     ServerEntry.Text = text;
     ServerEntry.Enabled = state == FieldState.Enabled;
     ServerEntry.ExampleText = example_text;
 }
Ejemplo n.º 26
0
        public static void RefreshBoard(GoBoardControl boardControl, IObservableGameTreeNavigator <MCTreeSearchNode <GameState, FieldCoordinates>, GameState, FieldCoordinates> navigator)
        {
            GameState currentState   = navigator.CurrentNode.State;
            var       allowedActions = currentState.GetAllowedActions();

            for (uint y = 0; y < boardControl.BoardSize; y++)
            {
                for (uint x = 0; x < boardControl.BoardSize; x++)
                {
                    FieldCoordinates field      = FieldCoordinates.Get(x, y);
                    FieldState       fieldState = currentState.InternalState.BoardFields[x, y];
                    boardControl.Fields[x, y].State = fieldState;
                    boardControl.Fields[x, y].Labels.Clear();
                    // Illegal
                    boardControl.Fields[x, y].Borders[0] = fieldState == FieldState.Empty ? allowedActions.Contains(field) == false : false;
                    boardControl.Fields[x, y].Borders[1] = false;
                    boardControl.Fields[x, y].Borders[2] = false;
                }
            }

            var currentNode = navigator.CurrentNode;

            //double[] mctsWeights = null;// mcts.Selector.GetWeights(mcts.CurrentNode);

            if (currentNode.Children != null)
            {
                foreach (var childNode in currentNode.Children)
                {
                    if (childNode.Key != FieldCoordinates.Pass)
                    {
                        if (childNode.Value.Visits > 0)
                        {
                            boardControl.Fields[childNode.Key.X, childNode.Key.Y].AddLabel(Brushes.Magenta, $"{childNode.Value.Visits}");
                            boardControl.Fields[childNode.Key.X, childNode.Key.Y].AddLabel(Brushes.Green, $"{childNode.Value.Value}");
                        }
                    }
                }

                var mostFrequentlySimulated = currentNode.Children.Where(w => w.Key != FieldCoordinates.Pass && w.Value.Visits > 0).MaxItems(i => i.Value.Visits);

                foreach (var mostItem in mostFrequentlySimulated)
                {
                    boardControl.Fields[mostItem.Key.X, mostItem.Key.Y].Borders[2] = true;
                }
            }

            //if (mctsWeights != null)
            //{
            //    mctsWeights = mctsWeights.Where(w => w.Item1.LastAction != null && w.Item1.LastAction != FieldCoordinates.Pass);
            //
            //    foreach (var item in mctsWeights)
            //    {
            //        var move = item.Item1.LastAction;
            //
            //        if (move != null && move != FieldCoordinates.Pass)
            //        {
            //            boardControl.Fields[move.X, move.Y].AddLabel(Brushes.Blue, $"{item.Item2:f2}");
            //        }
            //    }
            //
            //    var maxItem = mctsWeights.MaxItem(i => i.Item2);
            //    var maxMove = maxItem.Item1.LastAction;
            //
            //    boardControl.Fields[maxMove.X, maxMove.Y].Borders[1] = true;
            //}

            boardControl.Refresh();
        }
Ejemplo n.º 27
0
 public Capture(FieldState[,] boardState)
 {
     BoardState = boardState;
 }
Ejemplo n.º 28
0
 public bool SetState(Piece piece, FieldState state)
 {
     return(SetState(piece.Row, piece.Column, state));
 }
Ejemplo n.º 29
0
 private void AddFields(List <CustomFieldObject> FieldList, int NumberOfFields, FieldState fieldState)
 {
     for (int i = 0; i < NumberOfFields; i++)
     {
         FieldList.Add(CreateField(fieldState));
     }
 }
Ejemplo n.º 30
0
 public bool SetState(int r, int c, FieldState state)
 {
     board[r, c] = state;
     return(true);
 }
Ejemplo n.º 31
0
 public static bool IsPiece(FieldState state)
 {
     return(state == FieldState.Red || state == FieldState.RedKing || state == FieldState.Black || state == FieldState.BlackKing);
 }
Ejemplo n.º 32
0
 public static bool IsOfColor(Player player, FieldState state)
 {
     return((player == Player.Black && (state == FieldState.Black || state == FieldState.BlackKing)) ||
            (player == Player.Red && (state == FieldState.Red || state == FieldState.RedKing)));
 }
Ejemplo n.º 33
0
 public CellGroupManager(FieldState state)
 {
     _width   = state.Width;
     _height  = state.Height;
     _ourSign = state.PlayerSign;
 }
Ejemplo n.º 34
0
        public static void RefreshBoard(GoBoardControl playoutBoardControl, GamePlayoutNode <GameState, FieldCoordinates> node)
        {
            if (node != null)
            {
                for (uint y = 0; y < playoutBoardControl.BoardSize; y++)
                {
                    for (uint x = 0; x < playoutBoardControl.BoardSize; x++)
                    {
                        var        field      = playoutBoardControl.Fields[x, y];
                        FieldState fieldState = node.State.InternalState.BoardFields[x, y];
                        field.State = fieldState;
                        field.Labels.Clear();
                        field.Label.Text = string.Empty;
                        field.Borders[0] = false;
                        field.Borders[1] = false;
                        field.Borders[2] = false;
                    }
                }

                foreach (var field in node.State.GetAllowedActionsForRandomPlayout())
                {
                    if (field != FieldCoordinates.Pass)
                    {
                        playoutBoardControl.Fields[field.X, field.Y].Borders[2] = true;
                    }
                }

                var path = node.GetPath();
                int num  = 1;

                foreach (var item in path)
                {
                    if (item.LastAction != null && item.LastAction != FieldCoordinates.Pass)
                    {
                        var field = playoutBoardControl.Fields[item.LastAction.X, item.LastAction.Y];
                        //field.State = item.GameState.CurrentPlayer.Opposite.Color.State;

                        switch (item.Type)
                        {
                        case GamePlayoutNodeType.Selected:
                            field.Borders[0] = true;
                            break;

                        case GamePlayoutNodeType.Expanded:
                            field.Borders[1] = true;
                            break;

                        case GamePlayoutNodeType.Playout:
                            if (field.Label.Text == string.Empty)
                            {
                                field.Label.Text = $"{num++}";
                            }
                            else
                            {
                                field.Label.Text = $",{num++}";
                            }
                            break;
                        }
                    }
                }

                //if (selectedRound.Value.Path != null)
                //{
                //
                //}
                //
                //foreach (var item in selectedRound.Value.Selection.Where(p => p.LastAction != null && p.LastAction != FieldCoordinates.Empty))
                //{
                //    var field = playoutBoardControl.Fields[item.LastAction.X, item.LastAction.Y];
                //    field.State = item.GameState.CurrentPlayer.Opposite.Color.State;
                //    field.Borders[0] = true;
                //}
                //
                //if (selectedRound.Value.Expansion != null)
                //{
                //    var node = selectedRound.Value.Expansion;
                //    var field = playoutBoardControl.Fields[node.LastAction.X, node.LastAction.Y];
                //    field.State = node.GameState.CurrentPlayer.Opposite.Color.State;
                //    field.Borders[1] = true;
                //}
                //
                //int num = 1;
                //
                //foreach (var item in selectedRound.Value.Playout.Where(p => p.Item1 != null && p.Item1 != FieldCoordinates.Empty))
                //{
                //    var field = playoutBoardControl.Fields[item.Item1.X, item.Item1.Y];
                //    field.State = item.Item2.CurrentPlayer.Opposite.Color.State;
                //    field.AddLabel(Brushes.Gray, $"{num}");
                //    num++;
                //}

                playoutBoardControl.Refresh();
            }
        }
Ejemplo n.º 35
0
 public void SetupState(FieldState state)
 {
     piece.SetColor(state);
     Selectable = state == FieldState.SELECTABLE;
 }
        int getFieldStateID(string stateInWords)
        {
            FieldState requistedFieldState = TipezeNyumbaServiceUnitOfWork.Repository <FieldState>().Get(u => u.state == stateInWords);

            return(requistedFieldState.fieldStateID);
        }
Ejemplo n.º 37
0
 public void PlaceShip(Guid shipId)
 {
     State  = FieldState.SHIP;
     ShipId = shipId;
 }
Ejemplo n.º 38
0
 public Field(int?idOfTheShip, FieldState fieldState)
 {
     this.IdOfTheShip = idOfTheShip;
     this.State       = fieldState;
 }
Ejemplo n.º 39
0
 public BoardField(int x, int y)
 {
     X           = x;
     Y           = y;
     _fieldState = FieldState.Empty;
 }
Ejemplo n.º 40
0
 public Field(FieldBuilder builder, PropertyBuilder property, FieldState state)
 {
     Builder  = builder;
     Property = property;
     State    = state;
 }
 void ChangePathFieldEvent(string text, string example_text, FieldState state)
 {
     FolderEntry.Text = text;
     FolderEntry.Enabled = state == FieldState.Enabled;
     FolderEntry.ExampleText = example_text;
 }
Ejemplo n.º 42
0
 public bool IsInsideAndHasState(uint x, uint y, FieldState stone)
 {
     return(Inside(x, y) && BoardFields[x, y] == stone);
 }
Ejemplo n.º 43
0
 public abstract Cell GetNextMove(FieldState fieldState);
Ejemplo n.º 44
0
 public override Cell GetNextMove(FieldState fieldState)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 45
0
 public static void AddMove(GlobalState state, FieldState fromField, List <(string, List <FieldState>)> moveList, string endPos)
Ejemplo n.º 46
0
 public bool InitAndValid(FieldState[,] boardArray)
 {
     InitBoard(boardArray);
     return InitialValid();
 }
Ejemplo n.º 47
0
 public void SetState(FieldState state)
 {
     State = state;
 }
Ejemplo n.º 48
0
 public void InitBoard(FieldState[,] boardArray)
 {
     _gameState = new GameState(boardArray);
     Console.WriteLine("Init new Board");
     Console.WriteLine("Current player: {0}", _gameState.CurrentPlayer + 1);
 }
Ejemplo n.º 49
0
        public void SetItemValue(DataField field, FieldState state)
        {
            var item = ModelItem;

            item.SetPropertyValue(field.BindingProperty, state.Value);
        }
Ejemplo n.º 50
0
 private void RaiseBoardChangedEvent(FieldState[,] board)
 {
     if (BoardChanged != null)
     {
         BoardChanged(this, board);
     }
 }
Ejemplo n.º 51
0
 private void GameOnGameCompleted(object sender, FieldState e)
 {
     App.RunOnUiThread(() => DrawState(e));
 }
Ejemplo n.º 52
0
        /*
         * A GameEnd függyvény megvizsgálja a beérkező x, y pozíciók alapján, hogy a lépést végrehajtó játékosnak összegyűlt-e a szükséges mennyiségű szomszédos lépése.
         * Igaz értéket ad vissza ha összegyűlt, tehát a játéknak vége.
         * Hamis értéket ad vissza ha még nem gyűlt össze.
         * Paraméterei:
         * x: Amely sorba a játékos megtette lépését.
         * y: Amely oszlopba a játékos megtette lépését.
         * step: Ahány szomszédos lépésnek össze kell gyűlnie a nyereséghez.
         */
        static bool GameEnd(GridModel table, int x, int y, int step)
        {
            int testx = x, testy = y, borderx = 0, bordery = 0;
            int sum = 0;

            int[] testdirx = { 0, 0, 1, -1, -1, 1, 1, -1 };
            int[] testdiry = { 1, -1, 0, 0, 1, -1, 1, -1 };

            FieldState prev = table[x, y];

            for (int i = 0; i < 8; i++)
            {
                switch (testdirx[i])
                {
                case -1:
                    borderx = -1;
                    break;

                case 0:
                    borderx = -2;
                    break;

                case 1:
                    borderx = table.Height;
                    break;
                }
                switch (testdiry[i])
                {
                case -1:
                    bordery = -1;
                    break;

                case 0:
                    bordery = -2;
                    break;

                case 1:
                    bordery = table.Width;
                    break;
                }

                while (!(testy == bordery || testx == borderx || table[testx, testy] != prev || sum == step))
                {
                    sum++;
                    testx += testdirx[i];
                    testy += testdiry[i];
                }

                if ((i + 1) % 2 == 0 && (sum - 1) >= step)
                {
                    return(true);
                }
                else if ((i + 1) % 2 == 0 && (sum - 1) < step)
                {
                    sum = 0;
                }

                testx = x;
                testy = y;
            }

            return(false);
        }
Ejemplo n.º 53
0
        public void Shoot_WhenCalled_ShouldProperlyChangeFieldState(FieldState initialState, FieldState expectedState)
        {
            var field = new Field(initialState);

            var returnedState = field.Shoot();

            field.State.Should().Be(expectedState);
        }
Ejemplo n.º 54
0
 private bool BoardIsNew(FieldState[,] boardArray)
 {
     return (GetDiff(_gameState.BoardArray, boardArray).Count > 0);
 }
Ejemplo n.º 55
0
        private void _validationWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!_validationWorker.CancellationPending)
            {
                #region Some Shit

                Image<Bgr, Byte> ImageFrameClone = CurrentCapture.Copy(new Rectangle(0, 0, 480, 480));

                Tuple<FieldCounter[,], Image<Bgr, Byte>> result = getFileStateTabel(ImageFrameClone);
                ImageFrameClone = result.Item2;

                FieldState[,] fieldStareTable;
                fieldStareTable = new FieldState[8, 8];
                bool playerMakeMove = false;

                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        int[] fieldValues = { result.Item1[i, j].white, result.Item1[i, j].black, result.Item1[i, j].red, result.Item1[i, j].green, result.Item1[i, j].blue, result.Item1[i, j].yellow, result.Item1[i, j].undefined };
                        int dominationColor = fieldValues.Max();

                        if (result.Item1[i, j].white == dominationColor)
                        {
                            fieldStareTable[i, j] = FieldState.Empty;
                        }
                        else if (result.Item1[i, j].black == dominationColor)
                        {
                            fieldStareTable[i, j] = FieldState.Empty;
                        }
                        else if (result.Item1[i, j].red == dominationColor)
                        {
                            fieldStareTable[i, j] = FieldState.RedPawn;
                        }
                        else if (result.Item1[i, j].green == dominationColor)
                        {
                            fieldStareTable[i, j] = FieldState.GreenPawn;
                        }
                        else if (result.Item1[i, j].yellow == dominationColor)
                        {
                            fieldStareTable[i, j] = FieldState.YellowPawn;
                        }
                        else if (result.Item1[i, j].blue == dominationColor)
                        {
                            fieldStareTable[i, j] = FieldState.BluePawn;
                        }
                        else if (result.Item1[i, j].undefined == dominationColor)
                        {
                            playerMakeMove = true;
                            break;
                        }
                    }
                    if (playerMakeMove)
                    {
                        break;
                    }
                }

                if (!playerMakeMove)
                {
                    RaiseBoardChangedEvent(fieldStareTable);
                }

                RaiseValidatedImageChangedEvent(ImageFrameClone.Bitmap);
                #endregion
            }
        }
Ejemplo n.º 56
0
 public Field(FieldState state)
 {
     State = state;
 }
Ejemplo n.º 57
0
 public Player(FieldState state)
 {
     Id    = Guid.NewGuid();
     State = state;
 }
Ejemplo n.º 58
0
        /*
         * Az AI függvény a megkapott tábla alapján a referencia szerint érkező aix, aiy pozíciók értékét meghatározza,
         * így ad választ a játékosok lépéseire.
         * Paraméterei:
         * -CPU: az a FieldState változó ami az AIhoz tartozik.
         */
        static void AI(GridModel table, FieldState CPU, ref int aix, ref int aiy)
        {
            List <int> lx = new List <int>();
            List <int> ly = new List <int>();

            int[]  testdirx = { 0, -1, -1, -1, 0, 1, 1, 1 };
            int[]  testdiry = { -1, -1, 0, 1, 1, 1, 0, -1 };
            Random rnd      = new Random();
            int    choice;

            //Összegyűjti a már meglévő lépéseket a táblán.
            for (int i = 1; i < table.Height - 1; i++)
            {
                for (int j = 1; j < table.Width - 1; j++)
                {
                    if (table[i, j] != FieldState.None)
                    {
                        for (int k = 0; k < 8; k++)
                        {
                            if (table[i + testdirx[k], j + testdiry[k]] == FieldState.None)
                            {
                                lx.Add(i + testdirx[k]);
                                ly.Add(j + testdiry[k]);
                            }
                        }
                    }
                }
            }

            for (int i = 1; i < table.Height - 1; i++)
            {
                if (table[i, 0] != FieldState.None && table[i, 1] == FieldState.None)
                {
                    lx.Add(i);
                    ly.Add(1);
                }
                if (table[i, table.Width - 1] != FieldState.None && table[i, table.Width - 2] == FieldState.None)
                {
                    lx.Add(i);
                    ly.Add(table.Width - 2);
                }
            }

            for (int i = 1; i < table.Width - 1; i++)
            {
                if (table[0, i] != FieldState.None && table[1, i] == FieldState.None)
                {
                    lx.Add(0);
                    ly.Add(i);
                }
                if (table[table.Height - 1, i] != FieldState.None && table[table.Height - 2, i] == FieldState.None)
                {
                    lx.Add(table.Height - 2);
                    ly.Add(i);
                }
            }

            if (table[0, 0] != FieldState.None)
            {
                for (int i = 4; i <= 6; i++)
                {
                    if (table[0 + testdirx[i], 0 + testdiry[i]] == FieldState.None)
                    {
                        lx.Add(0 + testdirx[i]);
                        ly.Add(0 + testdiry[i]);
                    }
                }
            }
            if (table[0, table.Width - 1] != FieldState.None)
            {
                for (int i = 6; i <= 8; i++)
                {
                    if (table[0 + testdirx[i % 8], table.Width - 1 + testdiry[i % 8]] == FieldState.None)
                    {
                        lx.Add(0 + testdirx[i % 8]);
                        ly.Add(table.Width - 1 + testdiry[i % 8]);
                    }
                }
            }
            if (table[table.Height - 1, 0] != FieldState.None)
            {
                for (int i = 2; i <= 4; i++)
                {
                    if (table[table.Height - 1 + testdirx[i], 0 + testdiry[i]] == FieldState.None)
                    {
                        lx.Add(table.Height - 1 + testdirx[i]);
                        ly.Add(0 + testdiry[i]);
                    }
                }
            }
            if (table[table.Height - 1, table.Width - 1] != FieldState.None)
            {
                for (int i = 0; i <= 2; i++)
                {
                    if (table[table.Height - 1 + testdirx[i], table.Width - 1 + testdiry[i]] == FieldState.None)
                    {
                        lx.Add(table.Height - 1 + testdirx[i]);
                        ly.Add(table.Width - 1 + testdiry[i]);
                    }
                }
            }

            //Ha nem üres a tábla, random választ egy elemet az összegyűjtött pozíciók listájából.
            //Ha üres akkor a tábla közepére helyezi lépését.
            if (lx.Count == 0)
            {
                aix = table.Height / 2;
                aiy = table.Width / 2;
            }
            else
            {
                choice = rnd.Next(0, lx.Count);
                aix    = lx[choice];
                aiy    = ly[choice];
            }
        }
 private CustomFieldObject CreateField(FieldState fieldState)
 {
     return new CustomFieldObject() { FieldState = fieldState };
 }
Ejemplo n.º 60
0
 public bool IsOutsideOrHasState(uint x, uint y, FieldState stone)
 {
     return(Inside(x, y) == false || BoardFields[x, y] == stone);
 }