protected GamePlayStrategyInfo(BoardBase board, int playerId, Guid playerGuid, int gameId, TeamColor team)
 {
     Board      = board;
     PlayerId   = playerId;
     PlayerGuid = playerGuid;
     GameId     = gameId;
     Team       = team;
 }
Exemple #2
0
        public override Strategy GetStrategyFor(PlayerBase player, BoardBase board, Guid playerGuid, int gameId,
                                                List <PlayerBase> players)
        {
            if (player.Role == PlayerType.Member || players.Count <= 2)
            {
                return(new NormalPlayerStrategy(player, board, playerGuid, gameId));
            }

            return(new LeaderStrategy(player, board, playerGuid, gameId));
        }
        private void CheckIfCloser(BoardBase board, Location newLocation, ref int distanceToNearest,
                                   Direction direction, ref Direction directionToNearest)
        {
            var taskField = board[newLocation] as TaskField;

            if (taskField != null)
            {
                if (taskField.DistanceToPiece < distanceToNearest)
                {
                    distanceToNearest  = taskField.DistanceToPiece;
                    directionToNearest = direction;
                }
            }
        }
Exemple #4
0
    public void Refresh <T>(T owner) where T : IObj
    {
        if (owner == null)
        {
            return;
        }
        BoardBase board = null;

        mBoards.TryGetValue(owner, out board);
        if (board != null)
        {
            board.Refresh();
        }
    }
Exemple #5
0
    public void Release <T>(T owner) where T : IObj
    {
        if (owner == null)
        {
            return;
        }
        BoardBase board = null;

        mBoards.TryGetValue(owner, out board);
        if (board != null)
        {
            board.Release();
        }
        mBoards.Remove(owner);
    }
        public IEnumerable <Cell> WhereToPlaceShip(IShip ship, BoardBase board)
        {
            CurrentBoard = board;

            IEnumerable <Cell> shipLocation = null;

            // Seed the randome number generator..
            Random rand = new Random(Guid.NewGuid().GetHashCode());

            // Select a random row/column and orientation
            // If none of the proposed cells are occupied, place the ship

            while (true)    //TODO - what happens if we never find a place for the ship !
            {
                var startcolumn = rand.Next(1, board.BoardSize + 1);
                var startrow    = rand.Next(1, board.BoardSize);
                var endrow      = startrow;
                var endcolumn   = startcolumn;

                bool horizontal = Convert.ToBoolean(rand.Next(2));  // 0 or 1
                if (horizontal)
                {
                    endcolumn += ship.Width - 1;
                }
                else
                {
                    endrow += ship.Width - 1;
                }

                // Check that the strategy hasnt broken any game rules...
                // TODO - MAKE THESE RULES OF THE GAME THAT ALL STRATEGIES SHOULD CHECK !
                if (IsOutOfBounds(endrow, endcolumn))
                {
                    continue;
                }
                if (IsOccupied(startrow, startcolumn, endrow, endcolumn))
                {
                    continue;
                }

                // Return the ship location
                shipLocation = CurrentBoard.Cells.Range(startrow, startcolumn, endrow, endcolumn);

                break;
            }
            return(shipLocation);
        }
Exemple #7
0
        public async Task UpdateBoardAsync(User user, BoardBase board)
        {
            if (!IsIn(user))
            {
                return;
            }

            List <(string UserName, BoardBase Board)> boardList = null;

            lock (UserBoardState)
            {
                UserBoardState[user] = board;
                boardList            = UserBoardState.Select(x => (x.Key.Name.Name, x.Value)).ToList();
            }

            await UserList.Broadcast(u => u.SendBoardUpdated(boardList));
        }
Exemple #8
0
        public NormalPlayerStrategy(PlayerBase player, BoardBase board, Guid playerGuid, int gameId)
        {
            var teamCoefficient        = player.Team == TeamColor.Blue ? 0 : 1;
            var offset                 = teamCoefficient * (board.TaskAreaSize + board.GoalAreaSize);
            var undiscoveredGoalFields = new List <GoalField>();

            for (var i = 0; i < board.Width; ++i)
            {
                for (var j = offset; j < offset + board.GoalAreaSize; ++j)
                {
                    undiscoveredGoalFields.Add(board[new Location(i, j)] as GoalField);
                }
            }

            undiscoveredGoalFields.Shuffle();

            NormalPlayerStrategyInfo = new NormalPlayerStrategyInfo(board, player.Id, playerGuid, gameId, player.Team,
                                                                    undiscoveredGoalFields);
        }
 private void MainForm_Load(object sender, EventArgs e)
 {
     _chess = new Chess(this);
 }
 public abstract Strategy GetStrategyFor(PlayerBase player, BoardBase board, Guid playerGuid, int gameId,
                                         List <PlayerBase> players);
Exemple #11
0
 public BasicStrategy(PlayerBase player, BoardBase board, Guid playerGuid, int gameId) : base(player, board,
                                                                                              playerGuid, gameId)
 {
     BasicStrategyInfo = new BasicStrategyInfo(board, player.Id, playerGuid, gameId, player.Team,
                                               NormalPlayerStrategyInfo.UndiscoveredGoalFields);
 }
Exemple #12
0
 public Player()
 {
     this.score       = 0;
     this.ready       = false;
     this.playerBoard = new BoardBase();
 }
 public override Strategy GetStrategyFor(PlayerBase player, BoardBase board, Guid playerGuid, int gameId,
                                         List <PlayerBase> playerBases)
 {
     return(new BasicStrategy(player, board, playerGuid, gameId));
 }
 public NormalPlayerStrategyInfo(BoardBase board, int playerId, Guid playerGuid, int gameId, TeamColor team,
                                 List <GoalField> undiscoveredGoalFields) : base(board, playerId, playerGuid, gameId, team)
 {
     UndiscoveredGoalFields           = undiscoveredGoalFields;
     _skippedKnowledgeExchangeCounter = 0;
 }
Exemple #15
0
    public void Create <T>(T owner, EBoardType type) where T : IObj
    {
        //if (owner == null || owner.CacheTransform == null)
        //{
        //    return;
        //}
        if (mBoards.ContainsKey(owner))
        {
            return;
        }
        BoardBase  board = null;
        GameObject go    = null;
        string     path  = null;

        Define.BOARDPATHS.TryGetValue(type, out path);
        Debug.LogError(path);
        if (string.IsNullOrEmpty(path))
        {
            return;
        }
        go = ZTPool.Instance.GetGo(path);
        switch (type)
        {
        case EBoardType.TYPE_PLAYER:
            if (owner is Actor)
            {
                board = go.GET <BoardPlayer>();
            }
            break;

        case EBoardType.TYPE_NPC:
            if (owner is Actor)
            {
                board = go.GET <BoardNpc>();
            }
            break;

        case EBoardType.TYPE_MONSTER:
            if (owner is Actor)
            {
                board = go.GET <BoardMonster>();
            }
            break;

        case EBoardType.TYPE_PORTAL:
            //if (owner is LevelPortal)
            //{
            //    BoardPortal item = go.GET<BoardPortal>();
            //    board = item;
            //}
            break;
        }
        if (board != null)
        {
            //BaseWindow window = ZTUIManager.Instance.GetWindow<UIBoard>(WindowID.UI_BOARD);
            //if(window.IsVisable()==false)
            //{
            //    window = ZTUIManager.Instance.OpenWindow(WindowID.UI_BOARD);
            //}
            //if(window.CacheTransform!=null)
            //{
            //    board.transform.SetParent(window.CacheTransform);
            //    NGUITools.SetLayer(board.gameObject, window.CacheTransform.gameObject.layer);
            //}
            board.transform.SetParent(Laucher.instance.uiboad);
            board.transform.localScale = new Vector3(1, 1, 1);

            board.SetOwner(owner);
            board.UpdatePosition(owner.CacheTransform);
            board.Init();
            board.Refresh();
            board.Path    = path;
            board.enabled = true;
            board.SetVisbale(false);
            board.SetVisbale(true);
            mBoards.Add(owner, board);
        }
    }
 public LeaderStrategyInfo(BoardBase board, int playerId, Guid playerGuid, int gameId, TeamColor team,
                           List <GoalField> undiscoveredGoalFields) : base(board, playerId, playerGuid, gameId, team, undiscoveredGoalFields)
 {
 }