示例#1
0
 protected void Executor_MoveStartedEvent(PlayerColor player, TileScheme tile)
 {
     Socket.SendToAll(new ServerResponse()
     {
         Type   = ServerResponseType.MOVE_START,
         Color  = player,
         Scheme = tile
     });
 }
示例#2
0
 protected void Executor_TilePlacedEvent(PlayerColor player, TileScheme tile, Coords coords, TileOrientation orientation)
 {
     Socket.SendToAll(new ServerResponse()
     {
         Type        = ServerResponseType.TILE_PLACEMENT,
         Color       = player,
         Coords      = coords,
         Scheme      = tile,
         Orientation = orientation
     });
 }
 private void Simulation_MoveStartedEvent(PlayerColor player, TileScheme scheme)
 {
     if (_Running)
     {
         _Serializer.Serialize(_Writer, new ServerResponse()
         {
             Type   = ServerResponseType.MOVE_START,
             Color  = player,
             Scheme = scheme
         });
     }
 }
 private void Simulation_TilePlacedEvent(PlayerColor player, TileScheme scheme, Coords coords, TileOrientation orientation)
 {
     if (_Running)
     {
         _Serializer.Serialize(_Writer, new ServerResponse()
         {
             Type        = ServerResponseType.TILE_PLACEMENT,
             Color       = player,
             Scheme      = scheme,
             Coords      = coords,
             Orientation = orientation
         });
     }
 }
        /// <summary>
        /// Performs action on start of the move.
        /// </summary>
        /// <param name="scheme">Scheme of the tile.</param>
        /// <param name="color">Color of the player making the move.</param>
        private void MoveStart(TileScheme scheme, PlayerColor color)
        {
            CurrentTileRectangle.SetLayout(scheme, TileOrientation.N);

            // If player was not on move and now he is
            if (CurrentOnMove != PlayerColor && PlayerColor == color)
            {
                // Clicking enabled on empty places
                foreach (var r in EmptyTiles.Values)
                {
                    r.MouseEventEnabled = true;
                    r.Visibility        = Visibility.Visible;
                }
            }
            // Else if player was on move and now he is not
            else if (CurrentOnMove == PlayerColor && PlayerColor != color)
            {
                PassMoveBtn.IsEnabled = false;

                if (PlacedTiles.TryGetValue(CurrentCoords, out TileRectangle currentTile))
                {
                    currentTile.RegionMouseEventEnabled = false;
                }

                foreach (var c in PlacedFollowerPositions)
                {
                    PlacedTiles[c].FollowerMouseEventEnabled = false;
                }
            }

            // Set on move
            foreach (var pair in PlayerScoreRecords)
            {
                pair.Value.OnMove = (pair.Key == color);
            }

            CurrentOnMove = color;
            CurrentScheme = scheme;
        }
        /// <summary>
        /// Performs tile placement.
        /// </summary>
        /// <param name="color">Color of the player making the move.</param>
        /// <param name="scheme">Scheme of the tile.</param>
        /// <param name="coords">Coordinates of the tile.</param>
        /// <param name="orientation">Orientation of the tile.</param>
        private void PlaceTile(PlayerColor color, TileScheme scheme, Coords coords, TileOrientation orientation)
        {
            // Place the tile
            TileRectangle newRectangle = new TileRectangle();

            newRectangle.SetLayout(scheme, orientation);

            Canvas.SetLeft(newRectangle, coords.X * 100);
            Canvas.SetTop(newRectangle, coords.Y * 100);

            newRectangle.Coords = coords;

            TilesCanvas.Children.Add(newRectangle);

            PlacedTiles.Add(coords, newRectangle);

            // Remove empty tile and create new
            if (EmptyTiles.ContainsKey(coords))
            {
                TilesCanvas.Children.Remove(EmptyTiles[coords]);
                EmptyTiles.Remove(coords);
            }

            foreach (var or in new TileOrienationEnumerator())
            {
                var neigh = coords.GetNeighbouringCoords(or);

                if (!PlacedTiles.ContainsKey(neigh) && !EmptyTiles.ContainsKey(neigh))
                {
                    var emptyTile = new EmptyTileRectangle(neigh);
                    emptyTile.MouseClick += EmptyTile_MouseClick;
                    EmptyTiles.Add(neigh, emptyTile);

                    Canvas.SetLeft(emptyTile, neigh.X * 100);
                    Canvas.SetTop(emptyTile, neigh.Y * 100);

                    emptyTile.Visibility = Visibility.Collapsed;

                    TilesCanvas.Children.Add(emptyTile);
                }

                PassMoveBtn.IsEnabled = true;
            }

            CurrentCoords = coords;

            // If player is on move
            if (CurrentOnMove == PlayerColor)
            {
                // Activate the tile to be clicked on (placing follower)
                newRectangle.RegionMouseEventEnabled = true;
                newRectangle.RegionMouseClick       += PlacedTile_RegionMouseClick;

                // Deactivate empty tiles
                foreach (var et in EmptyTiles.Values)
                {
                    et.MouseEventEnabled = false;
                    et.Visibility        = Visibility.Collapsed;
                }

                // Activate the tiles with followers
                foreach (var c in PlacedFollowerPositions)
                {
                    PlacedTiles[c].FollowerMouseEventEnabled = true;
                }
            }
        }
示例#7
0
        /// <summary>
        /// Asks player for move.
        /// </summary>
        /// <param name="tile">Tile to be placed.</param>
        /// <param name="tilePlacement">Tile placement part of the move.</param>
        /// <param name="followerPlacement">Follower placement part of the move.</param>
        public void GetMove(TileScheme tile, out PlayerRequest tilePlacement, out PlayerRequest followerPlacement)
        {
            var grid = _Executor.CurrentGameState.Grid;

            List <Tuple <Coords, TileOrientation> > tilePlacementPossibilities = new List <Tuple <Coords, TileOrientation> >();

            foreach (var baseCoords in grid.Keys)
            {
                // Check all possible placements = places neighbouring already placed tiles
                foreach (var neighOr in new TileOrienationEnumerator())
                {
                    var coords = baseCoords.GetNeighbouringCoords(neighOr);

                    // If tile is already placed, skip
                    if (grid.ContainsKey(coords))
                    {
                        continue;
                    }

                    // Check all orientations of the tile
                    foreach (var orientation in new TileOrienationEnumerator())
                    {
                        // If cannot be placed, skip
                        try
                        {
                            GridExplorer.CheckTilePlacement(grid, tile, coords, orientation, false);
                            tilePlacementPossibilities.Add(new Tuple <Coords, TileOrientation>(coords, orientation));
                        }
                        catch (GameException)
                        {
                        }
                    }
                }
            }


            // Select one possibility
            var selected = tilePlacementPossibilities[_Random.Next(tilePlacementPossibilities.Count)];


            tilePlacement = new PlayerRequest()
            {
                Type        = PlayerRequestType.TILE_PLACEMENT,
                Color       = Color,
                Coords      = selected.Item1,
                Orientation = selected.Item2,
                Scheme      = tile
            };

            // Make fake executor
            GameExecutor executor = new GameExecutor();

            executor.CurrentGameState = _Executor.CurrentGameState.Copy();
            executor.ChangeTileSetType(TileSetType.PASSIVE);
            executor.PlaceTile(Color, tile, selected.Item1, selected.Item2);

            var newState = executor.CurrentGameState;

            followerPlacement = new PlayerRequest()
            {
                Type  = PlayerRequestType.NO_FOLLOWER_PLACEMENT,
                Color = Color
            };

            // Compute best move for followers
            int bestFollowerMoveValue = -1;

            // If can place
            if (newState.PlacedFollowers.Where(p => p.Color == Color).Count() < newState.Params.FollowerAmount)
            {
                for (int i = 0; i < tile.RegionCount; i++)
                {
                    if (!GridExplorer.IsRegionOccupied(newState.Grid, selected.Item1, i))
                    {
                        int newScore = GridExplorer.GetPointsForFollower(newState.Grid, selected.Item1, i, false);

                        if (newScore > bestFollowerMoveValue)
                        {
                            bestFollowerMoveValue      = newScore;
                            followerPlacement.Type     = PlayerRequestType.FOLLOWER_PLACEMENT;
                            followerPlacement.Coords   = selected.Item1;
                            followerPlacement.RegionId = i;
                        }
                    }
                }
            }

            // For all own placed folowers
            foreach (var fp in newState.PlacedFollowers.Where(p => p.Color == Color))
            {
                int newScore = -1;

                switch (newState.Grid[fp.TileCoords].Scheme.GetRegionType(fp.RegionId))
                {
                case RegionType.MOUNTAIN:
                    if (GridExplorer.IsRegionClosed(newState.Grid, fp.TileCoords, fp.RegionId))
                    {
                        newScore = 2;     // If placing is for at least 2, it is good! (else get out of here)
                    }
                    else if (GridExplorer.GetPointsForFollower(newState.Grid, fp.TileCoords, fp.RegionId, false) < 2)
                    {
                        newScore = 1;     // If there are too few points, get out of here
                    }
                    else
                    {
                        newScore = -1;     // Else you can wait with this follower
                    }
                    break;

                case RegionType.SEA:
                case RegionType.GRASSLAND:
                    if (GridExplorer.IsRegionClosed(newState.Grid, fp.TileCoords, fp.RegionId))
                    {
                        newScore = 3;     // If placing is for at least 3, it is good! (else get out of here)
                    }
                    else if (GridExplorer.GetPointsForFollower(newState.Grid, fp.TileCoords, fp.RegionId, false) < 2)
                    {
                        newScore = 1;     // If there are too few points, get out of here
                    }
                    else
                    {
                        newScore = -1;
                    }
                    break;
                }

                if (newScore > bestFollowerMoveValue)
                {
                    bestFollowerMoveValue    = newScore;
                    followerPlacement.Type   = PlayerRequestType.FOLLOWER_REMOVEMENT;
                    followerPlacement.Coords = fp.TileCoords;
                }
            }
        }
示例#8
0
 /// <summary>
 /// Tells player that tile is placed.
 /// </summary>
 /// <param name="color">Color of the player making the move.</param>
 /// <param name="tile">Scheme of tile that was placed.</param>
 /// <param name="coordinates">Coodrinates of the placed tile.</param>
 /// <param name="orientation">Orientation of the placed tile.</param>
 public void PlaceTile(PlayerColor color, TileScheme tile, Coords coordinates, TileOrientation orientation)
 {
     _Executor.PlaceTile(color, tile, coordinates, orientation);
 }