Example #1
0
        /// <summary>
        /// public wrapper for recursion
        /// try each possible move, find the one with the best score
        /// </summary>
        /// <param name="lookahead">how far to look ahead</param>
        /// <param name="playerX">is this for player x</param>
        /// <returns>The data on the best move location and score</returns>
        public MinimaxResult DoMinimax(int lookahead, bool playerX)
        {
            // set up inital state
            DateTime startTime = DateTime.Now;

            if (lookahead < 1)
            {
                throw new Exception("Invalid lookahead of " + lookahead);
            }

            this.debugDataItems.Clear();

            Occupied player = playerX.ToPlayer();
            int      alpha  = MoveScoreConverter.ConvertWin(player.Opponent(), 0);
            int      beta   = MoveScoreConverter.ConvertWin(player, 0);

            MinimaxResult bestMove = this.ScoreBoard(lookahead, this.ActualBoard, playerX, alpha, beta);

            if (bestMove.Move != Location.Null)
            {
                GoodMoves.AddGoodMove(0, bestMove.Move);
            }

            DateTime endTime = DateTime.Now;

            this.MoveTime = endTime - startTime;

            return(bestMove);
        }
Example #2
0
        public void SaveToXML(XmlElement objStar)
        {
            var xeOrbit = objStar.OwnerDocument.CreateElement("Orbit");

            objStar.AppendChild(xeOrbit);
            Common.CreateTextNode(xeOrbit, "Type", OrbitalType.ToString());
            Common.CreateTextNode(xeOrbit, "Occupied", Occupied.ToString());

            if (Occupied == OccupiedBy.CAPTURED)
            {
                Common.CreateTextNode(xeOrbit, "Number", World.OrbitNumber.ToString());
            }
            else
            {
                Common.CreateTextNode(xeOrbit, "Number", Number.ToString());
            }

            Common.CreateTextNode(xeOrbit, "Range", Range.ToString());
            Common.CreateTextNode(xeOrbit, "HasWorld", (World != null).ToString());

            if (World != null)
            {
                World.SaveToXML(xeOrbit);
            }
        }
Example #3
0
    //Instatiates a nature object to the cell
    private void AddNature(GameObject nature, Occupied occupyingType)
    {
        var spawnPosition = new Vector3(transform.position.x, 0 + nature.transform.localScale.y / 2, transform.position.z);

        mOccupyingObject = Instantiate(nature, spawnPosition, Quaternion.Euler(Vector3.zero)) as GameObject;
        mOccupied        = occupyingType;
    }
Example #4
0
 public Cell(Cell originalCell)
 {
     if (originalCell != null)
     {
         this.location   = originalCell.location;
         this.IsOccupied = originalCell.IsOccupied;
     }
 }
Example #5
0
 public static void InsertOccuiped(Occupied occupied)
 {
     try
     {
         DBManager.GetOccupiedCollection().InsertOne(occupied);
     }
     catch { }
 }
Example #6
0
        private static int NegateForPlayerY(int score, Occupied player)
        {
            if (player == Occupied.PlayerY)
            {
                return(score * -1);
            }

            return(score);
        }
Example #7
0
        public Tile(Texture2D _texture, Texture2D _cartasian_texture, Rectangle _cartasianRectangle, int _id)

        {
            teleport_tile      = false;
            id                 = _id;
            tileSize           = _cartasianRectangle.Width;
            texture            = _texture;
            cartasian_texture  = _cartasian_texture;
            cartasianRectangle = _cartasianRectangle;
            occupied           = Occupied.no;
            color              = Color.White;
            isHidden           = true;
        }
Example #8
0
    private void Start()
    {
        stats = GetComponent<Stats> ();
        uMC = GetComponent<UnitMovementController> ();
        uJC = GetComponent<UnitJobController> ();

        idle = new Idle (this);
        occupied = new Occupied (this);
        returnHome = new ReturnHome (this);
        fullfilingNeeds = new FullfilingNeeds (this);

        currentState = idle;
    }
Example #9
0
        private static void ShowBestMove(HexBoardViewModel boardViewModel, Occupied player)
        {
            const int MaxSkillLevel = 6;

            for (int skillLevel = 1; skillLevel <= MaxSkillLevel; skillLevel++)
            {
                int currentSkillLevel = skillLevel;
                Action <ComputerMoveData> finishedAction = cmd => ShowBestMoveCompleted(cmd, boardViewModel, currentSkillLevel);

                ComputerMoveCalculator computerMoveCalculatorX = new ComputerMoveCalculator(boardViewModel.Game, finishedAction, skillLevel);
                computerMoveCalculatorX.ForcePlayer = player;
                computerMoveCalculatorX.Move();
            }
        }
Example #10
0
        public static Occupied Opponent(this Occupied player)
        {
            switch (player)
            {
            case Occupied.PlayerX:
                return(Occupied.PlayerY);

            case Occupied.PlayerY:
                return(Occupied.PlayerX);

            default:
                throw new Exception("No opponent for Occupied " + player);
            }
        }
Example #11
0
 public static string OccupiedToString(Occupied occupied)
 {
     switch (occupied)
     {
         case Occupied.Empty:
             return "-";
         case Occupied.PlayerX:
             return "X";
         case Occupied.PlayerY:
             return "Y";
         default:
             return "?";
     }
 }
Example #12
0
 //Convert ReservedStand object to Occuiped obj in order to set the stand to be occuiped in the date that as given in each order item.
 public static Occupied Convert_ReservedStandToOccupied(ReservedStand RS, ObjectId OrderId)
 {
     if (RS != null)
     {
         Occupied item = new Occupied()
         {
             OrderID     = OrderId.ToString(),
             CheckIn     = RS.CheckIn,
             CheckOut    = RS.CheckOut,
             StandID     = RS.StandID,
             StandType   = RS.StandType,
             WorkSpaceID = RS.WorkSpaceID
         };
         return(item);
     }
     return(null);
 }
Example #13
0
        public static string OccupiedToString(Occupied occupied)
        {
            switch (occupied)
            {
            case Occupied.Empty:
                return("-");

            case Occupied.PlayerX:
                return("X");

            case Occupied.PlayerY:
                return("Y");

            default:
                return("?");
            }
        }
Example #14
0
        public MinimaxResult DoMinimax(int depth, bool isComputer)
        {
            // megmondja, hogy ki a jatekos, ha a gep, akkor az isComputerben true van, es akkor a plyaerben xPlayer lesz.
            Occupied player = isComputer.ToPlayer();

            // a gep az alpha
            this.alpha = MoveScoreConverter.ConvertWin(player.Opponent(), 0);
            // ember a beta
            this.beta = MoveScoreConverter.ConvertWin(player, 0);
            // a minimax algoritmus magaban
            MinimaxResult bestMove = this.MiniMaxAlg(depth, isComputer, board);

            if (bestMove.Move != Location.Null)
            {
                // killer heurisztika
                GoodMoves.AddGoodMove(0, bestMove.Move);
            }
            return(bestMove);
        }
Example #15
0
        public static bool IsImmediateWin(Occupied player, int score)
        {
            if (!IsWinForPlayer(score, player))
            {
                return(false);
            }

            if (player == Occupied.PlayerX)
            {
                return(WinDepth(score) == 0);
            }

            if (player == Occupied.PlayerY)
            {
                return(WinDepth(score) == 0);
            }

            return(false);
        }
Example #16
0
        public static bool IsImmediateWin(Occupied player, int score)
        {
            if (!IsWinForPlayer(score, player))
            {
                return false;
            }

            if (player == Occupied.PlayerX)
            {
                return WinDepth(score) == 0;
            }

            if (player == Occupied.PlayerY)
            {
                return WinDepth(score) == 0;
            }

            return false;
        }
Example #17
0
 //Set Stand as occuiped will set each stand in the order to be occuiped.
 //in order to prevent dupllicates
 public static bool SetStandsAsOccuiped(Order order)
 {
     try
     {
         if (order != null)
         {
             foreach (ReservedStand RS in order.StandsInOrder)
             {
                 Occupied o = Convert_ReservedStandToOccupied(RS, order.ID);
                 InsertOccuiped(o);
             }
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.StackTrace);
     }
 }
Example #18
0
        public BattleTile(Panel panelIn, Occupied state, int height, int width, int x, int y, int mapSquare, RichTextBox rtbbattleMonitor, BattleTile selectedTile, List <Gladiator> myTeam, List <Gladiator> enemyTeam, BattleTile[,] arena, int yHeight)
        {
            Button           = new Button();
            gladiator        = null;
            Height           = height;
            Width            = width;
            TopLoc           = height * y;
            LeftLoc          = width * x;
            X                = x + 1;
            Y                = yHeight - y;
            rtbBattleMonitor = rtbbattleMonitor;
            SelectedTile     = selectedTile;
            MyTeam           = myTeam;
            EnemyTeam        = enemyTeam;
            ArenaField       = arena;

            Button.Click += new EventHandler(buttonClicked);

            switch (mapSquare)
            {
            case 0:
            {
                Button.BackColor = Color.Aqua;
                break;
            }

            case 1:
            {
                Button.BackColor = Color.Aquamarine;
                break;
            }
            }
            Button.Height = Height;
            Button.Width  = Width;
            Button.Left   = LeftLoc;
            Button.Top    = TopLoc;

            Button.Refresh();
        }
        private Location GetBestMove(MinimaxResult playResult)
        {
            Location result = playResult.Move;

            int moveScore = playResult.Score;

            this.IsGameWon = MoveScoreConverter.IsWin(moveScore) && MoveScoreConverter.WinDepth(moveScore) == 1;

            Occupied opponent   = (!this.hexGame.PlayerX).ToPlayer();
            bool     losingMove = MoveScoreConverter.Winner(playResult.Score) == opponent;

            if (losingMove)
            {
                Location losingLocation = this.MakeLosingMove();
                if (losingLocation != Location.Null)
                {
                    result = losingLocation;
                }
            }

            return(result);
        }
Example #20
0
        public int SituationScore()
        {
            int playerXScore = this.xPathLength.PlayerScore(true);

            if (playerXScore == 0)
            {
                this.winner = Occupied.PlayerX;
                return(this.board.Size);
            }

            if (playerXScore == PathLengthConstants.OffPath)
            {
                this.winner = Occupied.PlayerY;
                return(-this.board.Size);
            }
            // compare the path lengths to see who is ahead
            int playerYScore = this.yPathLength.PlayerScore(false);

            this.winner = Occupied.Empty;

            return(playerYScore - playerXScore);
        }
Example #21
0
 private static void AssertWinner(int score, Occupied winner)
 {
     Assert.IsTrue(MoveScoreConverter.IsWin(score), "Should have winner");
     Assert.AreEqual(winner, MoveScoreConverter.Winner(score), "Wrong winner");
 }
Example #22
0
 public void SetOccupationStatus(Occupied occupied)
 {
     mOccupied = occupied;
 }
Example #23
0
 public static int ConvertWin(Occupied winner, int depth)
 {
     int result = (WinScore + MaxDepth) - depth;
     return NegateForPlayerY(result, winner);
 }
Example #24
0
 public static bool IsPlayerX(this Occupied player)
 {
     return(player == Occupied.PlayerX);
 }
Example #25
0
        private static int NegateForPlayerY(int score, Occupied player)
        {
            if (player == Occupied.PlayerY)
            {
                return score * -1;
            }

            return score;
        }
Example #26
0
        /// <summary>
        /// The path length is the measure of who is winning
        /// if a player's path length is zero
        /// they have connected the opposite sides,
        /// thier opponent cannot do so (ininite path length)
        /// and they have won 
        /// </summary>
        /// <returns>the score for the current state of play</returns>
        public int SituationScore()
        {
            int playerXScore = this.xPathLength.PlayerScore(true);

            if (playerXScore == 0)
            {
                this.winner = Occupied.PlayerX;
                return this.board.Size;
            }

            if (playerXScore == PathLengthConstants.OffPath)
            {
                this.winner = Occupied.PlayerY;
                return -this.board.Size;
            }

            // compare the path lengths to see who is ahead
            int playerYScore = this.yPathLength.PlayerScore(false);
            this.winner = Occupied.Empty;

            return playerYScore - playerXScore;
        }
Example #27
0
        private Turn TakeTurn(int column, Occupied occupied)
        {
            ValidateRange(column);

            var columnEnumerator = new ColumnEnumerator(this, column);

            var availableLocation = columnEnumerator.LastOrDefault(location => location.Occupied == Occupied.None);
            if (availableLocation == null) // column full
                return Turn.InvalidTurn;

            availableLocation.Occupied = occupied;

            TurnCount++;
            IsNextTurnRed = !IsNextTurnRed;
            IsNextTurnYellow = !IsNextTurnYellow;

            IsWon = IsWinningTurn(availableLocation);
            return new Turn { Location = availableLocation, IsWinningTurn = IsWon, IsDraw = !IsWon && IsDraw, IsNextTurnRed = IsNextTurnRed, IsNextTurnYellow = IsNextTurnYellow };
        }
Example #28
0
        public static int ConvertWin(Occupied winner, int depth)
        {
            int result = (WinScore + MaxDepth) - depth;

            return(NegateForPlayerY(result, winner));
        }
Example #29
0
    // Callback for the snake timer.
    private void SnakeTimer(Object state)
    {
        // Bail out if the game is already over.
        if (gameOver)
        {
            return;
        }

        // Determine the new position of the head, and the "piece"
        // to place at the old position of the head.
        int      newX  = headX;
        int      newY  = headY;
        Occupied piece = Occupied.Piece_NextLeft;

        switch (direction)
        {
        case Direction.Left:
        {
            --newX;
            piece = Occupied.Piece_NextLeft;
        }
        break;

        case Direction.Right:
        {
            ++newX;
            piece = Occupied.Piece_NextRight;
        }
        break;

        case Direction.Up:
        {
            --newY;
            piece = Occupied.Piece_NextUp;
        }
        break;

        case Direction.Down:
        {
            ++newY;
            piece = Occupied.Piece_NextDown;
        }
        break;
        }

        // Determine the new tail location.
        int newTailX = tailX;
        int newTailY = tailY;

        switch (occupied[tailX + tailY * width])
        {
        case Occupied.Piece_NextLeft:
        {
            --newTailX;
        }
        break;

        case Occupied.Piece_NextRight:
        {
            ++newTailX;
        }
        break;

        case Occupied.Piece_NextUp:
        {
            --newTailY;
        }
        break;

        case Occupied.Piece_NextDown:
        {
            ++newTailY;
        }
        break;
        }

        // Determine if there is a blockage at the new head position.
        bool needStar = false;

        if (newX < 0 || newX >= width ||
            newY < 0 || newY >= height)
        {
            // We've run into an outer wall.
            GameOver();
            return;
        }
        else if (occupied[newX + newY * width] == Occupied.Star)
        {
            // We've just collected a star: make us longer.
            newTailX = tailX;
            newTailY = tailY;
            needStar = true;
            ++score;
        }
        else if (occupied[newX + newY * width] != Occupied.Empty)
        {
            // We've run into ourselves or an inner wall.
            GameOver();
            return;
        }

        // Draw a new block at the head of the snake.
        if (!monochrome)
        {
            SetTextAttribute
                (ConsoleColor.DarkGreen, ConsoleColor.DarkGreen);
        }
        SetCursorPosition(newX + left, newY + top);
        Console.Write('#');
        occupied[headX + headY * width] = piece;
        occupied[newX + newY * width]   = piece;
        headX = newX;
        headY = newY;

        // Erase the block at the tail of the snake.
        if (newTailX != tailX || newTailY != tailY)
        {
            if (!monochrome)
            {
                SetTextAttribute
                    (ConsoleColor.Gray, ConsoleColor.Black);
            }
            SetCursorPosition(tailX + left, tailY + top);
            Console.Write(' ');
            occupied[tailX + tailY * width] = Occupied.Empty;
            tailX = newTailX;
            tailY = newTailY;
        }

        // Place a new star if we just ate one.
        if (needStar)
        {
            PlaceStar(true);
            PrintScore();
        }

        // Shift the cursor to get it out of the way.
        ShiftCursor();
    }
Example #30
0
        public static bool IsWinForPlayer(int score, Occupied player)
        {
            int positveScore = NegateForPlayerY(score, player);

            return(positveScore >= WinScore);
        }
Example #31
0
 public Cell(Location location)
 {
     this.location   = location;
     this.IsOccupied = Occupied.Empty;
 }
Example #32
0
    // Draw the board layout.
    private void DrawBoard()
    {
        int temp;

        // Clear the screen to the default attributes.
        SetTextAttribute(ConsoleColor.Gray, ConsoleColor.Black);
        Console.Clear();

        // Set the text attributes so that we get a solid rectangle
        // on color terminals, or regular line drawing characters
        // on monochrome terminals.
        if (!monochrome)
        {
            SetTextAttribute
                (ConsoleColor.DarkRed, ConsoleColor.DarkRed);
        }

        // Draw the top line.
        SetCursorPosition(left - 1, top - 1);
        Console.Write('+');
        for (temp = 0; temp < width; ++temp)
        {
            Console.Write('-');
        }
        Console.Write('+');

        // Draw the bottom line.
        SetCursorPosition(left - 1, top + height);
        Console.Write('+');
        for (temp = 0; temp < width; ++temp)
        {
            Console.Write('-');
        }
        Console.Write('+');

        // Draw the left and right sides.
        for (temp = 0; temp < height; ++temp)
        {
            SetCursorPosition(left - 1, top + temp);
            Console.Write('|');
            SetCursorPosition(left + width, top + temp);
            Console.Write('|');
        }

        // Draw all of the pieces on the board as it currently stands.
        int x, y;

        for (y = 0; y < height; ++y)
        {
            for (x = 0; x < width; ++x)
            {
                Occupied occ = occupied[x + y * width];
                if (occ == Occupied.Star)
                {
                    SetCursorPosition(left + x, top + y);
                    if (!monochrome)
                    {
                        SetTextAttribute
                            (ConsoleColor.DarkYellow,
                            ConsoleColor.Black);
                    }
                    Console.Write('*');
                }
                else if (occ == Occupied.Wall)
                {
                    SetCursorPosition(left + x, top + y);
                    if (!monochrome)
                    {
                        SetTextAttribute
                            (ConsoleColor.DarkRed,
                            ConsoleColor.DarkRed);
                    }
                    Console.Write('+');
                }
                else if (occ != Occupied.Empty)
                {
                    SetCursorPosition(left + x, top + y);
                    if (!monochrome)
                    {
                        SetTextAttribute
                            (ConsoleColor.DarkGreen,
                            ConsoleColor.DarkGreen);
                    }
                    Console.Write('#');
                }
            }
        }

        // Print the current score.
        PrintScore();

        // Shift the cursor out of the way.
        ShiftCursor();
    }
Example #33
0
 private bool CheckForSequence(IEnumerator<Location> enumerator, Occupied occupied)
 {
     int countInSequence = 0;
     while (enumerator.MoveNext())
     {
         if (occupied == enumerator.Current.Occupied)
         {
             countInSequence++;
             if (countInSequence == WinningSequenceLength)
                 return true;
         }
         else
         {
             // There is a break in a sequence, seeya.
             if (countInSequence > 0)
                 break;
         }
     }
     return false;
 }
Example #34
0
 private static void AssertWinner(int score, Occupied winner)
 {
     Assert.IsTrue(MoveScoreConverter.IsWin(score), "Should have winner");
     Assert.AreEqual(winner, MoveScoreConverter.Winner(score), "Wrong winner");
 }
Example #35
0
 public static bool IsWinForPlayer(int score, Occupied player)
 {
     int positveScore = NegateForPlayerY(score, player);
     return positveScore >= WinScore;
 }