Exemplo n.º 1
0
    private bool isBlockAbove()
    {
        bool flag = false;

        for (int y = Y; y >= 0; y--)
        {
            Tile tile = MyBoard.GetTile(X, y);
            if (tile != null)
            {
                Block bo = tile.GetBoardObect(TileLayer);
                if (bo != null && bo.State == BlockState.FALLING)
                {
                    flag = true;
                    break;
                }
            }
        }
        return(flag);
    }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            MyBoard    board    = new MyBoard(30, 10);
            DrawBoard  DelDraw  = MyDrawBoard;
            CheckInput DelCheck = MyCheckInput;

            DelDraw(board);
            board.Message();
            Console.SetCursorPosition(0, board.BoardSizeY + 1);
            MyClient Client = new MyClient();

            while (true)
            {
                Client.choice = MyCheckInput(board);
                DelDraw      += Client.ReturnChoice(Client.choice);
                DelDraw(board);
            }

            Console.ReadKey();
        }
Exemplo n.º 3
0
        private int[] ifOnlyOneHit()
        {
            int row;
            int col;

            int[] dir;
            int   count = 0;

            do
            {
                dir = MyBoard.ConvertDirectionInputToLoopInfo(count);
                row = LastHit[0] + dir[0];
                col = LastHit[1] + dir[1];
                count++;
                if (count > 5)
                {
                    return(resetLastHit());
                }
            } while (row < 1 || row > BoardSize || col < 1 || col > BoardSize || MyEnemyBoard.Matrix[row][col].HasBeenGuessed);
            return(new int[] { row, col });
        }
Exemplo n.º 4
0
Arquivo: Spawner.cs Projeto: lumoh/TT
    private void spawnBoardObject()
    {
        GameObject BoardObjectPrefab = Resources.Load <GameObject>(_spawnType);

        if (BoardObjectPrefab != null)
        {
            GameObject spawnedObject = Instantiate(BoardObjectPrefab);
            if (spawnedObject != null)
            {
                Block boardObject = spawnedObject.GetComponent <Block>();
                if (boardObject != null)
                {
                    boardObject.Init(ColorUtil.PickRandom(MyBoard.NumColors), TileLayer);
                    MyBoard.AddBoardObject(boardObject, X, Y, false);
                    boardObject.transform.position   = transform.position;
                    boardObject.transform.localScale = Vector3.zero;
                    LeanTween.scale(boardObject.gameObject, Vector3.one, 0.25f).setEase(LeanTweenType.easeOutSine);
                }
            }
        }
    }
Exemplo n.º 5
0
        void r_RSET(object sender, serverReturnEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(new Action(delegate()
            {
                Deck.Clear();
                Hand.Clear();
                MyBoard.Clear();
                OppBoard.Clear();
                Exile.Clear();
                Grave.Clear();
                MYPV  = 20;
                HISPV = 20;
            }), null);
            MoveToEventArgs args = new MoveToEventArgs("Room");
            EventHandler <MoveToEventArgs> handler = this.getMoveTo();

            if (handler != null)
            {
                handler(this, args);
            }
        }
Exemplo n.º 6
0
 public Tower(Color color, MyBoard board) : base(color, board)
 {
 }
Exemplo n.º 7
0
 public virtual Ship GetShot(Position targetPosition)
 {
     return(MyBoard.UpdateBoard(targetPosition));
 }
Exemplo n.º 8
0
 protected Hex findActiveHex(Point point)
 {
     return(MyBoard.findActiveHex(point));
 }
Exemplo n.º 9
0
 protected bool isPointOnBoard(Point point)
 {
     return(MyBoard.IsPointOnBoard(point));
 }
Exemplo n.º 10
0
        public override void Update(GameTime gameTime)
        {
            if (this.actionHasFinished)
            {
                return;
            }

            MouseState mouseStateCurrent = Mouse.GetState();

            if (actionIsTriggered)
            {
                if (!CurrentPlayer.IsMoving)
                {
                    // Player has stopped moving, so this action is complete.
                    combatActionHandler.handleActionComplete(actionType);
                    this.actionHasFinished = true;
                }
                else
                {
                    // Player is moving, so there isn't anything we need to do
                    return;
                }
            }
            else
            {
                if (!allowUserInteraction())
                {
                    // Current player is under computer control.
                    if (CurrentPlayer.MyType == Player.Type.Zombie)
                    {
                        Zombie zombie        = (Zombie)CurrentPlayer;
                        int    numHexesMoved = zombie.handleCombatChooseMove(this);
                        zombie.subtractActionPointsBy(numHexesMoved);
                        actionIsTriggered = true;
                    }
                }
                else
                {
                    // Current player is under user control.  Wait for a mouse click
                    // Show the path the user may want to take
                    // CombatLocation location = currentPlayer.Location;
                    //List<Hex> hexPath = this.board.highlightPath(location.i, location.j, mousePoint);

                    if (mouseStateCurrent.LeftButton == ButtonState.Pressed && mouseStatePrevious.LeftButton == ButtonState.Released)
                    {
                        Point mousePoint = new Point(mouseStateCurrent.X, mouseStateCurrent.Y);
                        Hex   targetHex  = getTargetHex(mousePoint);
                        if (targetHex != null)
                        {
                            GameEntity gameEntity = targetHex.MyGameEntity;
                            if (gameEntity != null)
                            {
                                actionIsTriggered = true;
                            }
                            else
                            {
                                actionIsTriggered = true;
                            }

                            if (actionIsTriggered)
                            {
                                int numHexesMoved = MyBoard.movePlayer(CurrentPlayer, mousePoint, this);

                                // Subtract the number spaces moved from the player's action points
                                CurrentPlayer.subtractActionPointsBy(numHexesMoved);
                            }
                        }
                    }
                }
            }

            mouseStatePrevious = mouseStateCurrent;
        }
Exemplo n.º 11
0
 private void highlightCurrentPlayer(bool highlight)
 {
     MyBoard.highlightCurrentPlayer(highlight);
 }
Exemplo n.º 12
0
        public int Search(int alpha, int beta, int depth)
        {
            Metrics.Nodes++;
            PvLength[Ply] = Ply;
            var inCheck = MyBoard.InCheck(MyBoard.SideToMove);
            int ext     = inCheck ? 1 : 0;

            if (MyGameState.GameBoard.History.IsPositionDrawn(MyBoard.HashKey))
            {
                return(CurrentDrawScore);
            }

            if (Ply >= MAX_DEPTH)
            {
                TakeBack();
                return(Evaluator.Evaluate(MyBoard, -10000, 10000));
            }

            if ((Metrics.Nodes & 65535) == 65535)
            {
                Interrupt();
                if (MyGameState.TimeUp)
                {
                    return(alpha);
                }
            }

            Move bestMove = null;

            if (depth + ext <= 0)
            {
                return(Quiesce(alpha, beta));
            }

            //first let's look for a transposition
            var entry = TranspositionTable.Instance.Read(MyBoard.HashKey);

            if (entry != null)
            {
                //we have a hit from the TTable
                if (entry.Depth >= depth)
                {
                    if (entry.Type == (byte)EntryType.CUT && entry.Score >= beta)
                    {
                        return(beta);
                    }
                    else if (entry.Type == (byte)EntryType.ALL && entry.Score <= alpha)
                    {
                        return(alpha);
                    }
                    else if (entry.Type == (byte)EntryType.PV)
                    {
                        return(entry.Score);
                    }
                }
            }

            int mateThreat   = 0;
            var myPieceCount = MyBoard.PieceCount(MyBoard.SideToMove);

            //next try a Null Move
            if (Ply > 0 &&
                depth > 1 &&
                alpha == beta - 1 &&
                !inCheck &&
                !MyBoard.History[Ply - 1].IsNullMove &&
                myPieceCount > 0 &&
                (myPieceCount > 2 || depth < 7))
            {
                Metrics.NullMoveTries++;
                MakeNullMove();
                var nullReductionDepth = depth > 6 ? 4 : 3;
                int nmScore;
                if (depth - nullReductionDepth - 1 > 0)
                {
                    nmScore = -Search(-beta, 1 - beta, depth - nullReductionDepth - 1);
                }
                else
                {
                    nmScore = -Quiesce(-beta, 1 - beta);
                }
                UnmakeNullMove();

                if (MyGameState.TimeUp)
                {
                    return(alpha);
                }

                if (nmScore >= beta)
                {
                    Metrics.NullMoveFailHigh++;
                    TranspositionTable.Instance.Store(MyBoard.HashKey, null, depth, nmScore, EntryType.CUT);
                    return(nmScore);
                }
            }

            var moves = MoveGenerator
                        .GenerateMoves(MyBoard)
                        .OrderByDescending((m) => OrderMove(m, entry));
            Move lastMove = null;
            int  lmr = 0, nonCaptureMoves = 0, movesSearched = 0;

            foreach (var m in moves)
            {
                bool fprune = false;
                int  score;
                if (!Make(m))
                {
                    continue;
                }

                var justGaveCheck = MyBoard.InCheck(MyBoard.SideToMove);
                var capture       = ((m.Bits & (byte)MoveBits.Capture) != 0);
                if (!capture && (entry == null || entry.MoveValue != m.Value)) // don't count the hash move as a non-capture
                {
                    ++nonCaptureMoves;                                         // while it might not be a capture, the point
                }
                // here is to start counting after generated captures
                var passedpawnpush = (m.Bits & (byte)MoveBits.Pawn) > 0 && (Evaluator.PassedPawnMask[MyBoard.SideToMove ^ 1, m.To] & MyBoard.Pawns[MyBoard.SideToMove]) == 0;
                //LATE MOVE REDUCTIONS
                if (ext == 0 &&          //no extension
                    !inCheck &&          //i am not in check at this node
                    !justGaveCheck &&    //the move we just made does not check the opponent
                    mateThreat == 0 &&   //no mate threat detected
                    !passedpawnpush &&   //do not reduce/prune passed pawn pushes
                    nonCaptureMoves > 0) //start reducing after the winning captures
                {
                    if (depth > 2)
                    {
                        lmr = movesSearched > 2 ? 2 : 1; // start reducing depth if we aren't finding anything useful
                    }
                    //FUTILITY PRUNING
                    else if (depth < 3 && alpha > -9900 && beta < 9900)
                    {
                        if (depth == 2 && -Evaluator.EvaluateMaterial(MyBoard) + Evaluator.PieceValues[(int)Piece.Rook] <= alpha)
                        {
                            Metrics.EFPrune++;
                            fprune = true;
                        }

                        else if (depth == 1 && -Evaluator.EvaluateMaterial(MyBoard) + Evaluator.PieceValues[(int)Piece.Knight] <= alpha)
                        {
                            Metrics.FPrune++;
                            fprune = true;
                        }
                    }
                }
                if (!fprune)
                {
                    //if we don't yet have a move, then search full window (PV Node)
                    if (bestMove == null)
                    {
                        score = -Search(-beta, -alpha, depth - 1 - lmr + ext);
                    }
                    else //otherwise, use a zero window
                    {
                        //zero window search
                        score = -Search(-alpha - 1, -alpha, depth - 1 - lmr + ext);

                        if (score > alpha)
                        {
                            //this move might be better than our current best move
                            //we have to research with full window

                            score = -Search(-beta, -alpha, depth - 1 - lmr + ext);

                            if (score > alpha && lmr > 0)
                            {
                                //let's research again without the lmr
                                Metrics.LMRResearch++;
                                score = -Search(-beta, -alpha, depth - 1);
                            }
                        }
                    }
                }
                else
                {
                    score = -Quiesce(-beta, -alpha);
                }

                TakeBack();
                ++movesSearched;
                if (MyGameState.TimeUp)
                {
                    return(alpha);
                }

                if (score >= beta)
                {
                    SearchFailHigh(m, score, depth, entry);
                    if (lastMove == null)
                    {
                        Metrics.FirstMoveFailHigh++;
                    }
                    return(score);
                }

                if (score > alpha)
                {
                    alpha    = score;
                    bestMove = m;
                    // PV Node
                    //update the PV
                    UpdatePv(bestMove);
                    //Add to hashtable
                    TranspositionTable.Instance.Store(
                        MyBoard.HashKey, bestMove, depth, alpha, TranspositionTableEntry.EntryType.PV);
                }

                lastMove = m;
            }

            //check for mate
            if (lastMove == null)
            {
                //we can't make a move. check for mate or stalemate.
                if (inCheck)
                {
                    return(-10000 + Ply);
                }
                else
                {
                    return(CurrentDrawScore);
                }
            }


            if (bestMove == null)
            {
                //ALL NODE
                TranspositionTable.Instance.Store(
                    MyBoard.HashKey, null, depth, alpha,
                    TranspositionTableEntry.EntryType.ALL);
            }

            return(alpha);
        }
Exemplo n.º 13
0
        public int SearchRoot(int alpha, int beta, int depth)
        {
            PvLength[0] = 0;

            if (MyGameState.GameBoard.History.IsGameDrawn(MyBoard.HashKey))
            {
                return(CurrentDrawScore);
            }

            if (RootMoves == null)
            {
                RootMoves = MoveGenerator
                            .GenerateMoves(MyBoard)
                            .OrderByDescending(m => OrderRootMove(m))
                            .ToList();
            }

            int  score;
            Move bestMove = null, lastMove = null;
            bool inCheck = MyBoard.InCheck(MyBoard.SideToMove);

            foreach (var m in RootMoves)
            {
                if (!Make(m))
                {
                    continue;
                }

                if (depth > 0)
                {
                    if (bestMove == null)
                    {
                        score = -Search(-beta, -alpha, depth - 1);
                    }
                    else
                    {
                        score = -Search(-alpha - 1, -alpha, depth - 1);
                        if (score > alpha)
                        {
                            score = -Search(-beta, -alpha, depth - 1);
                        }
                    }
                }
                else
                {
                    score = -Quiesce(-beta, -alpha);
                }

                TakeBack();

                if (MyGameState.TimeUp)
                {
                    return(alpha);
                }

                if (score >= beta)
                {
                    //we want to try this move first next time
                    NewRootMove(m);
                    PvLength[0] = 1;
                    PrincipalVariation[0, 0] = m;
                    return(score);
                }

                if (score > alpha)
                {
                    alpha    = score;
                    bestMove = m;
                    // PV Node
                    //update the PV
                    UpdatePv(bestMove);
                    TranspositionTable.Instance.Store(MyBoard.HashKey, m, depth, alpha, EntryType.PV);
                }

                lastMove = m;
            }

            //check for mate
            if (lastMove == null)
            {
                //we can't make a move. check for mate or stalemate.
                if (inCheck)
                {
                    return(-10000 + Ply);
                }
                else
                {
                    return(CurrentDrawScore);
                }
            }


            if (bestMove != null)
            {
                if (bestMove != RootMoves[0])
                {
                    NewRootMove(bestMove);
                }
            }
            return(alpha);
        }
Exemplo n.º 14
0
 private void TakeBack()
 {
     MyBoard.UnMakeMove();
     Ply--;
 }
Exemplo n.º 15
0
        public int Quiesce(int alpha, int beta)
        {
            Metrics.Nodes++;
            Metrics.QNodes++;

            if (Ply >= MAX_DEPTH)
            {
                TakeBack();
                return(Evaluator.Evaluate(MyBoard, -10000, 10000));
            }

            if ((Metrics.Nodes & 65535) == 65535)
            {
                Interrupt();
                if (MyGameState.TimeUp)
                {
                    return(alpha);
                }
            }
            int score = Evaluator.Evaluate(MyBoard, alpha, beta);

            if (score > alpha)
            {
                alpha = score;
            }
            //attemp to stand pat (don't search if eval tells us we are in a good position)
            var inCheck = MyBoard.InCheck(MyBoard.SideToMove);

            if (!inCheck)
            {
                if (score >= beta)
                {
                    return(beta);
                }

                //Don't bother searching if we are evaluating at less than a Queen
                if (score < alpha - Evaluator.PieceValues[(int)Piece.Queen])
                {
                    return(alpha);
                }
            }

            var moves = MoveGenerator
                        .GenerateCapturesAndPromotions(MyBoard, false)
                        .OrderByDescending((m) => OrderQuiesceMove(m));

            foreach (var m in moves)
            {
                if ((BitMask.Mask[m.To] & (MyBoard.King[0] | MyBoard.King[1])) > 0)
                {
                    return(beta);
                }

                //if SEE says this is a losing capture, we prune it
                if (StaticExchange.Eval(MyBoard, m, MyBoard.SideToMove) < 0)
                {
                    continue;
                }
                MyBoard.MakeMove(m, false);
                Ply++;

                score = -Quiesce(-beta, -alpha);
                TakeBack();
                if (score >= beta)
                {
                    return(beta);
                }
                if (score > alpha)
                {
                    alpha = score;
                }
            }
            return(alpha);
        }
Exemplo n.º 16
0
 public King(Color color, MyBoard board) : base(color, board)
 {
 }