Beispiel #1
0
        /// <summary>
        /// Display the status of the tile
        /// </summary>
        /// <param name="status">The status to set</param>
        /// <param name="warning">Number of warnings to show</param>
        public void SetStatus(TileStatus status, int warning = 0)
        {
            Image = null;
            switch (status)
            {
            case TileStatus.Unflippped:
                BackColor = Color.LightGray;
                Text      = string.Empty;
                break;

            case TileStatus.Flipped:
                BackColor = Color.White;
                break;

            case TileStatus.Flagged:
                Image = Properties.Resources.flag;
                break;

            case TileStatus.Warning:
                Text = warning.ToString();
                break;

            case TileStatus.Mine:
                Image = Properties.Resources.boom;
                break;
            }
        }
    public void Refresh()
    {
        if (m_Mat == null)
        {
            m_Mat = GetComponent <Renderer>().material;
        }
        if (Count <= 0 && Status != TileStatus.Bean)
        {
            PrevTile = null;
            Status   = TileStatus.Empty;
        }
        switch (Status)
        {
        case TileStatus.Empty:
            m_Mat.color = Color.white;
            break;

        case TileStatus.Snake:
            m_Mat.color = Color.yellow;
            break;

        case TileStatus.Bean:
            m_Mat.color = Color.green;
            break;
        }
        if (PrevTile && Count == PrevTile.Count)
        {
            PrevTile.Count--;
            PrevTile.Refresh();
        }
    }
Beispiel #3
0
        private void mark()
        {
            //toggle mark status
            switch (this.tileStatus)
            {
            case TileStatus.Normal:
                this.tileStatus = TileStatus.Marked;
                game.markedTiles.AddLast(this);
                setMarkAppearance();
                break;

            case TileStatus.Marked:
                this.tileStatus = TileStatus.Normal;
                game.markedTiles.Remove(this);
                setNormalAppearance();
                break;

            default:
                break;
            }

            //update score
            game.updateScore();

            //Check if termniate the game
            if (game.win())
            {
                game.endGame(300);
            }
        }
Beispiel #4
0
        private static void DrawTile(TileStatus tileStatus)
        {
            Console.Write("|");
            switch (tileStatus)
            {
            case TileStatus.OpenOcean:
                DrawOpenOceanTile();
                break;

            case TileStatus.Ship:
                DrawShipTile();
                break;

            case TileStatus.Hit:
                DrawHitTile();
                break;

            case TileStatus.Miss:
                DrawMissTile();
                break;

            case TileStatus.Sunk:
                DrawSunkTile();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tileStatus), tileStatus, null);
            }
            Console.Write("|");
        }
Beispiel #5
0
        public void dig()
        {
            this.tileStatus = TileStatus.Discovered;

            //remove handler
            this.MouseClick -= this.Tile_Click;

            // ask game to search potential expansion
            game.dig(this);

            //Change appearance
            switch (value)
            {
            case 0:
                this.BackColor = game.themeSetting.getTileDugColor();
                break;

            case 9:
                this.Text      = "★";
                this.BackColor = game.themeSetting.getMineDugColor();
                break;

            default:
                this.BackColor = game.themeSetting.getTileDugColor();
                this.Text      = value.ToString();
                break;
            }
            this.FlatAppearance.MouseOverBackColor = this.BackColor;
        }
Beispiel #6
0
//#endif

        void OnSingleTap(object sender, object args)
        {
//#if FIX_WINDOWS_DOUBLE_TAPS

            //    if (Device.OS == TargetPlatform.Windows || Device.OS == TargetPlatform.WinPhone)
            {
                if (lastTapSingle && DateTime.Now - lastTapTime < TimeSpan.FromMilliseconds(500))
                {
                    OnDoubleTap(sender, args);
                    lastTapSingle = false;
                }
                else
                {
                    lastTapTime   = DateTime.Now;
                    lastTapSingle = true;
                }
            }

//#endif

            switch (this.Status)
            {
            case TileStatus.Hidden:
                this.Status = TileStatus.Flagged;
                break;

            case TileStatus.Flagged:
                this.Status = TileStatus.Hidden;
                break;

            case TileStatus.Exposed:
                // Do nothing
                break;
            }
        }
Beispiel #7
0
    int boardEvaluation(TileStatus turn)
    {
        List <int> vertiMoves = possibleMoves(turn);
        List <int> horiMoves  = possibleMoves((TileStatus)(-(int)turn));

        return(vertiMoves.Count - horiMoves.Count);
    }
Beispiel #8
0
 public Tile(int row, int column, bool mine = false)
 {
     Row    = row;
     Column = column;
     Status = TileStatus.Hidden;
     Mine   = mine;
 }
Beispiel #9
0
        //public void ChangeTileStatus(TileStatus status)
        //{
        //    try
        //    {
        //        Debug.WriteLine($"Tile: ChangeTileStatus  {Tilestatus} to {status}");
        //        Tilestatus = status;
        //        //var source = emptyImageSource;
        //        ChangeTileImageVisible(status);
        //        //switch (status)
        //        //{
        //        //    case TileStatus.Empty:
        //        //        //source = emptyImageSource;
        //        //        break;

        //        //    case TileStatus.Black:
        //        //        //source = blackImageSource;
        //        //        break;

        //        //    case TileStatus.White:
        //        //        //source = whiteImageSource;
        //        //        break;
        //        //    case TileStatus.BlackGB:
        //        //        //source = gbXImageSource;
        //        //        break;
        //        //    case TileStatus.WhiteGB:
        //        //        //source = gbOImageSource;
        //        //        break;
        //        //}
        //        //Device.BeginInvokeOnMainThread(async () =>
        //        //{
        //        //    await ChangeSource(source);

        //        //});
        //        //Device.BeginInvokeOnMainThread(() =>
        //        //{
        //        //TileImage.SetValue(Image.SourceProperty, source);
        //        //Debug.WriteLine($"Tile: empty {emptyImageSource.Id} black {blackImageSource.Id} white {whiteImageSource.Id}");

        //        //});
        //        //Debug.WriteLine($"Tile: ChangeTileStatus  [{X},{Y}] ButtonStatus:{status }  TileImage  {source.Id}");
        //    }
        //    catch (Exception ex)
        //    {
        //        Debug.WriteLine(StaticClass.LogException("ChangeTileStatus", ex));
        //    }
        //}

        //private async Task ChangeSource(ImageSource source)
        //{
        //    TileImage.Source = source;

        //}
        //public void ChangeTileImageVisible(TileStatus status)
        //{
        //    switch (status)
        //    {
        //        case TileStatus.Empty:
        //            EmptyImage.IsVisible = true;
        //            BlackImage.IsVisible = false;
        //            WhiteImage.IsVisible = false;
        //            GbOImage.IsVisible = false;
        //            GbXImage.IsVisible = false;
        //            break;

        //        case TileStatus.Black:
        //            EmptyImage.IsVisible = false;
        //            BlackImage.IsVisible = true;
        //            WhiteImage.IsVisible = false;
        //            GbOImage.IsVisible = false;
        //            GbXImage.IsVisible = false;
        //            break;

        //        case TileStatus.White:
        //            EmptyImage.IsVisible = false;
        //            BlackImage.IsVisible = false;
        //            WhiteImage.IsVisible = true;
        //            GbOImage.IsVisible = false;
        //            GbXImage.IsVisible = false;
        //            break;
        //        case TileStatus.BlackGB:
        //            EmptyImage.IsVisible = false;
        //            BlackImage.IsVisible = false;
        //            WhiteImage.IsVisible = false;
        //            GbXImage.IsVisible = true;
        //            GbOImage.IsVisible = false;
        //            break;
        //        case TileStatus.WhiteGB:
        //            EmptyImage.IsVisible = false;
        //            BlackImage.IsVisible = false;
        //            WhiteImage.IsVisible = false;
        //            GbXImage.IsVisible = false;
        //            GbOImage.IsVisible = true;
        //            break;
        //    }


        //}
        public void SetTileImage(TileStatus status)
        {
            switch (status)
            {
            case TileStatus.Empty:
                TileImage.Source = emptyImageSource;
                break;

            case TileStatus.Black:
                TileImage.Source = blackImageSource;
                break;

            case TileStatus.White:
                TileImage.Source = whiteImageSource;
                break;

            case TileStatus.BlackGB:
                TileImage.Source = gbXImageSource;
                break;

            case TileStatus.WhiteGB:
                TileImage.Source = gbOImageSource;
                break;
            }
            Tilestatus = status;
        }
Beispiel #10
0
        /////////// Board Pattern //////////
        //
        //  [0] [1] [2]
        //  [3] [4] [5]
        //  [6] [7] [8]
        //
        public bool AddNewMills(ReactiveCollection <Tile> tiles, TileStatus ts, Tile movedTile)
        {
            Mill currentMill = null;

            checkMill(0, 1, 2, movedTile, ts, tiles, ref currentMill);
            checkMill(3, 4, 5, movedTile, ts, tiles, ref currentMill);
            checkMill(6, 7, 8, movedTile, ts, tiles, ref currentMill);

            checkMill(0, 3, 6, movedTile, ts, tiles, ref currentMill);
            checkMill(1, 4, 7, movedTile, ts, tiles, ref currentMill);
            checkMill(2, 5, 8, movedTile, ts, tiles, ref currentMill);

            // Check validity
            if (currentMill == null)
            {
                return(false);
            }
            currentMill.Turn = Turn;

            if (currentMill.First != movedTile &&
                currentMill.Second != movedTile &&
                currentMill.Third != movedTile)
            {
                return(false);
            }

            PreviousMills.Add(currentMill);

            return(true);
        }
Beispiel #11
0
    public List <int> possibleMoves(TileStatus turn)
    {
        List <int> moves = new List <int>();
        int        i, j;

        //count++;
        if (turn == TileStatus.VERTICAL)
        {
            for (i = 0; i < SIZE - 1; i++)
            {
                for (j = 0; j < SIZE; j++)
                {
                    if (logicBoard[i * SIZE + j] == TileStatus.EMPTY && logicBoard[i * SIZE + j + SIZE] == TileStatus.EMPTY)
                    {
                        moves.Add(i * SIZE + j);
                    }
                }
            }
        }
        else
        {
            for (i = 0; i < SIZE; i++)
            {
                for (j = 0; j < SIZE - 1; j++)
                {
                    if (logicBoard[i * SIZE + j] == TileStatus.EMPTY && logicBoard[i * SIZE + j + 1] == TileStatus.EMPTY)
                    {
                        moves.Add(i * SIZE + j);
                    }
                }
            }
        }
        return(moves);
    }
Beispiel #12
0
    public void PickTile(Vector2Int position)
    {
        if (SetTile(position) == true)
        {
            if (CheckIfWon(tiles) != TileStatus.None)
            {
                Debug.Log(currentPlayer.ToString() + " WON!");
                Reset();
                return;
            }
            else if (GetOpenTiles(tiles) <= 0)
            {
                Debug.Log("DRAW!");
                Reset();
                return;
            }
            currentPlayer = currentPlayer == TileStatus.X ? TileStatus.O : TileStatus.X;

            if (SetTile(AIMove()))
            {
                if (CheckIfWon(tiles) != TileStatus.None)
                {
                    Debug.Log(currentPlayer.ToString() + " WON!");
                    Reset();
                    return;
                }
                currentPlayer = currentPlayer == TileStatus.X ? TileStatus.O : TileStatus.X;
            }
        }
    }
Beispiel #13
0
        void OnSingleTap(object sender, object args)
        {
#if FIX_UWP_DOUBLE_TAPS
            if (Device.RuntimePlatform == Device.UWP)
            {
                if (lastTapSingle && DateTime.Now - lastTapTime < TimeSpan.FromMilliseconds(500))
                {
                    OnDoubleTap(sender, args);
                    lastTapSingle = false;
                }
                else
                {
                    lastTapTime   = DateTime.Now;
                    lastTapSingle = true;
                }
            }
#endif

            switch (this.Status)
            {
            case TileStatus.Hidden:
                this.Status = TileStatus.Flagged;
                break;

            case TileStatus.Flagged:
                this.Status = TileStatus.Hidden;
                break;

            case TileStatus.Exposed:
                // Do nothing
                break;
            }
        }
Beispiel #14
0
 /// <summary>
 /// Constructor for the BoardTile Class
 /// </summary>
 /// <param name="pos">The position to set the tile</param>
 public BoardTile(Vector2 pos)
 {
     position   = pos;
     status     = TileStatus.NONE;
     isOccupied = PieceColor.None;
     tileArea   = new Rectangle((int)pos.X * TILE_WIDTH, (int)pos.Y * TILE_HEIGHT, TILE_WIDTH, TILE_HEIGHT);
 }
Beispiel #15
0
    /// <summary>
    /// Status setters
    /// </summary>

    public void SetAsStart()
    {
        tileStatus = TileStatus.Start;

        //floor.GetComponent<MeshRenderer>().material.EnableKeyword("_EMISSION");
        //floor.GetComponent<MeshRenderer>().material.SetColor("_EmissionColor", Color.red);
    }
Beispiel #16
0
        public int Update(TileStatus newStatus, int surrondingMinesCount)
        {
            Status = newStatus;

            switch (Status)
            {
            case TileStatus.Unpressed:
                //display regular look
                return(0);

            case TileStatus.Pressed:
                if (Type == TileType.Empty)
                {
                    //update number on tile with surrongMinesCount
                    DisplayNumber(surrondingMinesCount);
                    return(0);
                }
                else
                {
                    //update mine picture
                    return(1);
                }

            case TileStatus.Flagged:
                //display flag on picturebox
                return(0);

            default:
                return(0);
            }
        }
Beispiel #17
0
 /// <summary>
 /// Copy constructor for the BoardTile class
 /// This constructor is used for the generation of temporary states
 /// </summary>
 /// <param name="tile">The tile to copy</param>
 public BoardTile(BoardTile tile)
 {
     position   = new Vector2(tile.position.X, tile.position.Y);
     status     = tile.status;
     isOccupied = tile.isOccupied;
     tileArea   = tile.tileArea;
 }
Beispiel #18
0
    private void DeserializeMap(string json)
    {
        MapJSON map = JsonConvert.DeserializeObject <MapJSON>(json);

        int x = map.mapRows.Length;
        int y = map.mapRows[0].row.Split(',').Length;

        TileValues = new int[x, y];

        for (int i = 0; i < x; i++)
        {
            string[] rowValues = map.mapRows[i].row.Split(',');
            for (int j = 0; j < y; j++)
            {
                int value;
                TileValues[i, j] = (int.TryParse(rowValues[j], out value) ? value : 0);

                if (TileValues[i, j] != 0)
                {
                    var mapPrefab = TileStatus.GetMapPrefabById(TileValues[i, j]);
                    Instantiate(mapPrefab, new Vector3(i * 1f, 0, j * 1f), Quaternion.identity);
                }
            }
        }
    }
Beispiel #19
0
        public TileStatus Search()
        {
            TileStatus status = MazeBot.TileStatus.Undefined;

            for (int x = 1; x < TileStatus.GetUpperBound(0); ++x)
            {
                for (int y = 1; y < TileStatus.GetUpperBound(1); ++y)
                {
                    if (TileStatus[x, y] == MazeBot.TileStatus.Goal)                     // if goal is found, move there
                    {
                        status = MoveTo(x, y);
                    }
                    else if (TileStatus[x, y] == MazeBot.TileStatus.Undefined)                     // else move to first unmapped tile.
                    {
                        status = MoveTo(x, y);
                    }
                    else
                    {
                        status = TileStatus[x, y];
                    }
                    if (status == MazeBot.TileStatus.Goal)
                    {
                        return(status);
                    }
                }
            }
            return(MazeBot.TileStatus.Undefined);
        }
Beispiel #20
0
 public void Flag()
 {
     if (Status != TileStatus.Shown)
     {
         Status = (Status != TileStatus.Flagged) ? TileStatus.Flagged : TileStatus.Hidden;
     }
 }
Beispiel #21
0
    public void DoHighLightPathTo(TileStatus tile)
    {
        tile.SetTarget(true);
        GetPlayerStatusScript().SetMoving(false);
        GetPlayerStatusScript().SetShowingPath(true);

        TileStatus next = tile;

        while (next != null)
        {
            next.SetPath(true);
            next.SetTarget(false);

            GetPath().Push(next.GetComponent <TileBFSScript>());
            if (next.GetComponent <TileBFSScript>().GetParent())
            {
                next = next.GetComponent <TileBFSScript>().GetParent().GetComponent <TileStatus>();
            }
            else
            {
                next = null;
            }
        }
        //Debug.Log("path.Count: "+path.Count);
    }
Beispiel #22
0
    public int MiniMax(TileStatus[,] board, TileStatus currentPlayer)
    {
        if (CheckIfWon(board) != TileStatus.None)
        {
            return((int)currentPlayer * (int)CheckIfWon(board));
        }

        Vector2Int move  = new Vector2Int(-1, -1);
        int        score = -2;

        for (int y = 0; y < 3; y++)
        {
            for (int x = 0; x < 3; x++)
            {
                if (board[x, y] == TileStatus.None)
                {
                    TileStatus[,] newBoard = (TileStatus[, ])board.Clone();
                    newBoard[x, y]         = currentPlayer;
                    int scoreForTheMove = -MiniMax(newBoard, (TileStatus)((int)currentPlayer * -1));
                    if (scoreForTheMove > score)
                    {
                        score = scoreForTheMove;
                        move  = new Vector2Int(x, y);
                    }
                }
            }
        }

        if (move == new Vector2Int(-1, -1))
        {
            return(0);
        }

        return(score);
    }
Beispiel #23
0
 // Use this for initialization
 void Start()
 {
     graphicBoard = GetComponent <BoardSetup>();
     logicBoard   = GetComponent <AI>();
     UpdatePanelData();
     currentTurn       = TileStatus.EMPTY;
     gameOverText.text = "";
 }
Beispiel #24
0
    public void SetAsEnd()
    {
        tileStatus = TileStatus.End;
        //floor.GetComponent<MeshRenderer>().material.EnableKeyword("_EMISSION");

        //floor.GetComponent<MeshRenderer>().material.SetColor("_EmissionColor", Color.green);
        goal.SetActive(true);
    }
Beispiel #25
0
 void Start()
 {
     status     = GetComponent <TileStatus>();
     renderer   = GetComponent <TileRenderer>();
     graphData  = GetComponent <TileGraphData>();
     searchData = GetComponent <TileUCSData>();
     AStarData  = GetComponent <TileAStarData>();
 }
 private void MoveTile(Vector3 startPosition, TileStatus tileStatus, TileScript destinationTile)
 {
     tileStatus.SetMoveTime();
     destinationTile.IsBlowable = false;
     destinationTile.SetPosition(startPosition);
     destinationTile.SetTile(tileStatus);
     StartCoroutine(InGameAnimationManager.Instance.MoveAnimation(destinationTile, destinationTile.GetTileVector()));
 }
Beispiel #27
0
 // Does not fire TileStatusChanged events.
 public void Initialize()
 {
     doNotFireEvent           = true;
     this.Status              = TileStatus.Hidden;
     this.IsBug               = false;
     this.SurroundingBugCount = 0;
     doNotFireEvent           = false;
 }
Beispiel #28
0
    public void Flag()
    {
        if (Status == TileStatus.Revealed)
        {
            throw new InvalidOperationException("Cannot flag a clicked tile.");
        }

        Status = TileStatus.Flagged;
    }
Beispiel #29
0
    public void UnFlag()
    {
        if (Status == TileStatus.Revealed)
        {
            throw new InvalidOperationException("Cannot un-flag a clicked tile.");
        }

        Status = TileStatus.Untouched;
    }
Beispiel #30
0
        public void TestDirectNoSolutionFound()
        {
            Game game = new Game();

            game.Initialize(MockData.NoSolutionXml);
            TileStatus result = game.Bot.MoveTo(game.GoalPosition.X, game.GoalPosition.Y);

            Assert.AreEqual(TileStatus.Undefined, result);
        }
Beispiel #31
0
 public Tile(int y,int x,GameObject l)
 {
     myTile = new GameObject("Tile ("+y+","+x+")");
     myTile.AddComponent<tk2dSprite>();
     myTile.AddComponent<tk2dSpriteAnimator>();
     myTile.GetComponent<tk2dSpriteAnimator>().Library = poisona;
     myTile.gameObject.transform.parent = l.transform;
     myStatus = new TileStatus(y,x);
     SetTileByStatus();
 }
Beispiel #32
0
    public Tile(int y,int x,GameObject l)
    {
        myTile = new GameObject("Tile ("+y+","+x+")");
        myTile.AddComponent<tk2dSprite>();
        myTile.AddComponent<tk2dSpriteAnimator>();
        myTile.GetComponent<tk2dSpriteAnimator>().Library = poisona;
        myTile.gameObject.transform.parent = l.transform;

        myStatus = new TileStatus(y,x,0);

        myHp = (GameObject)Instantiate(GameObject.Find ("Hp Label"));
        myHp.name = "Hp";
        myHp.transform.parent = myTile.transform;
        myHp.transform.localPosition = new Vector3(150,100,-1);
        myHp.GetComponent<UILabel>().color = new Color(255,255,255);

        HpImage = new GameObject("HpImage");
        HpImage.transform.parent = myTile.transform;
        HpImage.transform.localPosition = new Vector3(125,100,-1);
        HpImage.transform.localScale = new Vector3(0,0,0);
        HpImage.AddComponent<tk2dSprite>().SetSprite(datas,"Heart");

        myAttack = (GameObject)Instantiate (GameObject.Find ("Hp Label"));
        myAttack.name = "Atk";
        myAttack.transform.parent = myTile.transform;
        myAttack.transform.localPosition = new Vector3(150,-150,-1);

        AttackEffect = (GameObject)Instantiate(GameObject.Find ("Hp sample"));
        AttackEffect.name = "Atk_Eft";
        AttackEffect.transform.parent = myTile.transform;
        AttackEffect.transform.localPosition = new Vector3(0,0,-2);
        AttackEffect.transform.localScale = new Vector3(0,0,0);
        tk2dTextMesh tm = AttackEffect.GetComponent<tk2dTextMesh>();
        tm.anchor = TextAnchor.MiddleCenter;
        tm.text = "0";
        tm.Commit ();

        DieEffect = new GameObject("Die_Eft");
        DieEffect.transform.parent = myTile.transform;
        DieEffect.transform.localPosition = new Vector3(0,0,-2);
        DieEffect.transform.localScale = new Vector3(0,0,0);
        DieEffect.AddComponent<tk2dSprite>().SetSprite (datas,"X");

        SetHp();
        SetAtk();
        SetTileByStatus();
    }
Beispiel #33
0
 public void SetStatus(TileStatus status, int warning = 0)
 {
     switch(status)
     {
     default:
     case TileStatus.Unflippped:
         Text = string.Empty;break;
     case TileStatus.BadFlag:
         Text = "B";break;
     case TileStatus.Flag:
         Text = "F";break;
     case TileStatus.Warning:
         Text = warning.ToString();break;
     case TileStatus.Flipped:
         Text = ".";break;
     case TileStatus.TheMine:
         Text = "X";break;
     }
 }
Beispiel #34
0
 private void checkMill(int a, int b, int c, Tile movedTile, TileStatus ts,ReactiveCollection<Tile> tiles, ref Mill tofill)
 {
     if (tiles[a].Status == ts && tiles[b].Status == ts && tiles[c].Status == ts &&
         (movedTile == tiles[a] ||
          movedTile == tiles[b] ||
          movedTile == tiles[c]))
         tofill = new Mill(tiles[a], tiles[b], tiles[c]);
 }
Beispiel #35
0
 public void setTile(Point point, TileStatus ts)
 {
     Point p = new Point(point.X - offset_.X, point.Y - offset_.Y);
     tiles_[p.X, p.Y] = ts;
 }
 public void setTile(Point point, TileStatus status)
 {
     foreach (TileArea area in areas_)
     {
         if (area.isContained(point))
             area.setTile(point, status);
     }
 }
    /// <summary>
    /// Gets the path between two tile coordinates
    /// </summary>
    /// <returns>
    /// The path in tiles
    /// </returns>
    /// <param name='start'>
    /// Starting tile coordinate
    /// </param>
    /// <param name='end'>
    /// Ending tile coordinate
    /// </param>
    /// <param name='type'>
    /// Type of ground to consider for pathing
    /// </param>
    public static List<TileStatus> GetPath(Vector2 start, Vector2 end, TileStatus.GroundType type)
    {
        List<TileStatus> retn = new List<TileStatus>();
        TileStatus endNode = GetTileAt(end.x, end.y);
        TileStatus startNode = GetTileAt(start.x, start.y);

        Dictionary<TileStatus, AstarHelper> OpenNodes = new Dictionary<TileStatus, AstarHelper>();
        Dictionary<TileStatus, AstarHelper> ClosedNodes = new Dictionary<TileStatus, AstarHelper>();

        OpenNodes[startNode] = new AstarHelper();

        while(OpenNodes.Count > 0 && !OpenNodes.ContainsKey(endNode))
        {

            //Get the lowest cost Open Node
            int min = int.MaxValue;
            TileStatus lowest = null;
            foreach(TileStatus status in OpenNodes.Keys)
            {
                if(OpenNodes[status].combined < min)
                {
                    min = OpenNodes[status].combined;
                    lowest = status;
                }
            }

            //Compute the costs of the neighbors
            TileStatus up = GetTileAt(lowest.Position.x, lowest.Position.y + 1);
            TileStatus down = GetTileAt(lowest.Position.x, lowest.Position.y - 1);
            TileStatus left = GetTileAt(lowest.Position.x - 1, lowest.Position.y);
            TileStatus right = GetTileAt(lowest.Position.x + 1, lowest.Position.y);

            #region Up
            if(up != null && (up.groundType & type) != 0 && !ClosedNodes.ContainsKey(up))
            {
                AddNeighbor(OpenNodes, lowest, up, endNode);
            }
            #endregion

            #region down
            if(down != null && (down.groundType & type) != 0 && !ClosedNodes.ContainsKey(down))
            {
                AddNeighbor(OpenNodes, lowest, down, endNode);
            }
            #endregion

            #region left
            if(left != null && (left.groundType & type) != 0 && !ClosedNodes.ContainsKey(left))
            {
                AddNeighbor(OpenNodes, lowest, left, endNode);
            }
            #endregion

            #region right
            if(right != null && (right.groundType & type) != 0 && !ClosedNodes.ContainsKey(right))
            {
                AddNeighbor(OpenNodes, lowest, right, endNode);
            }
            #endregion

            ClosedNodes[lowest] = OpenNodes[lowest];
            OpenNodes.Remove(lowest);
        }

        if(!OpenNodes.ContainsKey(endNode)) return null;

        retn.Add(endNode);

        TileStatus nextNode = OpenNodes[endNode].prev;
        while(!retn.Contains(startNode))
        {
            retn.Insert(0, nextNode);
            nextNode = ClosedNodes[nextNode].prev;
        }

        //TODO: Complete this method

        return retn;
    }
Beispiel #38
0
 public void setLocalTile(Point p, TileStatus ts)
 {
     tiles_[p.X, p.Y] = ts;
 }
    void Awake()
    {
        Tiles = new TileStatus[(int)WorldSize.x, (int)WorldSize.y];

        for(int i = 0; i < WorldSize.x; i++)
            for(int j = 0; j < WorldSize.y; j++)
            {
                Tiles[i, j] = new TileStatus();
                Tiles[i, j].Position = new Vector2(i, j);
            }
    }
 private static void AddNeighbor(Dictionary<TileStatus, AstarHelper> OpenNodes, TileStatus lowest, TileStatus direction, TileStatus goal)
 {
     if(OpenNodes.ContainsKey(direction))
             {
                 AstarHelper helper = OpenNodes[direction];
                 helper.actual = OpenNodes[lowest].actual + GlobalConstants.A_STAR_MOVE_COST;
                 helper.prev = lowest;
                 OpenNodes[direction] = helper;
             }
             else
             {
                 AstarHelper helper = new AstarHelper();
                 helper.actual = OpenNodes[lowest].actual + GlobalConstants.A_STAR_MOVE_COST;
                 helper.heuristic = ManhattanDistance(direction.Position, goal.Position);
                 helper.prev = lowest;
                 OpenNodes[direction] = helper;
             }
 }
Beispiel #41
0
 public Tile()
 {
     OnHit = null;
     Status = TileStatus.OpenOcean;
 }
        void OnTileStatusChanged(object sender, TileStatus tileStatus)
        {
            if (isGameEnded)
                return;

            // With a first tile tapped, the game is now in progress.
            if (!isGameInProgress)
            {
                isGameInProgress = true;

                // Fire the GameStarted event.
                if (GameStarted != null)
                {
                    GameStarted(this, EventArgs.Empty);
                }
            }

            // Update the "flagged" bug count before checking for a loss.
            int flaggedCount = 0;

            foreach (Tile tile in tiles)
                if (tile.Status == TileStatus.Flagged)
                    flaggedCount++;

            this.FlaggedTileCount = flaggedCount;

            // Get the tile whose status has changed.
            Tile changedTile = (Tile)sender;

            // If it's exposed, some actions are required.
            if (tileStatus == TileStatus.Exposed)
            {
                if (!isGameInitialized)
                {
                    DefineNewBoard(changedTile.Row, changedTile.Col);
                    isGameInitialized = true;
                }

                if (changedTile.IsBug)
                {
                    isGameInProgress = false;
                    isGameEnded = true;

                    // Fire the GameEnded event!
                    if (GameEnded != null)
                    {
                        GameEnded(this, false);
                    }
                    return;
                }

                // Auto expose for zero surrounding bugs.
                if (changedTile.SurroundingBugCount == 0)
                {
                    CycleThroughNeighbors(changedTile.Row, changedTile.Col,
                        (neighborRow, neighborCol) =>
                        {
                            // Expose all the neighbors.
                            tiles[neighborRow, neighborCol].Status = TileStatus.Exposed;
                        });
                }
            }

            // Check for a win.
            bool hasWon = true;

            foreach (Tile til in tiles)
            {
                if (til.IsBug && til.Status != TileStatus.Flagged)
                    hasWon = false;

                if (!til.IsBug && til.Status != TileStatus.Exposed)
                    hasWon = false;
            }

            // If there's a win, celebrate!
            if (hasWon)
            {
                isGameInProgress = false;
                isGameEnded = true;

                // Fire the GameEnded event!
                if (GameEnded != null)
                {
                    GameEnded(this, true);
                }
                return;
            }
        }
 void OnDoubleTap(object sender, object args)
 {
     this.Status = TileStatus.Exposed;
 }
        void OnSingleTap(object sender, object args)
        {

#if FIX_ANDROID_DOUBLE_TAPS

            if (Device.OS == TargetPlatform.Android)
            {
                if (lastTapSingle && DateTime.Now - lastTapTime < TimeSpan.FromMilliseconds(500))
                {
                    OnDoubleTap(sender, args);
                    lastTapSingle = false;
                }
                else
                {
                    lastTapTime = DateTime.Now;
                    lastTapSingle = true;
                }
            }

#endif

            switch (this.Status)
            {
                case TileStatus.Hidden:
                    this.Status = TileStatus.Flagged;
                    break;

                case TileStatus.Flagged:
                    this.Status = TileStatus.Hidden;
                    break;

                case TileStatus.Exposed:
                    // Do nothing
                    break;
            }
        }
 // Does not fire TileStatusChanged events.
 public void Initialize()
 {
     doNotFireEvent = true;
     this.Status = TileStatus.Hidden;
     this.IsBug = false;
     this.SurroundingBugCount = 0;
     doNotFireEvent = false;
 }
Beispiel #46
0
 private void OnTileStatusChanged(TileStatus value)
 {
     if (value == TileStatus.Unoccupied)
         FillColor = UnoccupiedColor;
     if (value == TileStatus.P1)
         FillColor = P1Color;
     if (value == TileStatus.P2)
         FillColor = P2Color;
     this.RaiseAndSetIfChanged(ref tileStatus, value);
 }
Beispiel #47
0
        /////////// Board Pattern //////////
        //
        //  [0]           [1]            [2]
        //      [8]       [9]       [10]
        //           [16] [17] [18]
        //  [3] [11] [19]      [20] [12] [4]
        //           [21] [22] [23]
        //      [13]      [14]      [15]
        //  [5]           [6]            [7]
        //
        public bool AddNewMills(ReactiveCollection<Tile> tiles, TileStatus ts, Tile movedTile)
        {
            Mill currentMill = null;

            checkMill(0, 1, 2, movedTile, ts, tiles, ref currentMill);
            checkMill(0, 3, 5, movedTile, ts, tiles, ref currentMill);
            checkMill(2, 4, 7, movedTile, ts, tiles, ref currentMill);
            checkMill(5, 6, 7, movedTile, ts, tiles, ref currentMill);

            checkMill(8, 9, 10, movedTile, ts, tiles, ref currentMill);
            checkMill(8, 11, 13, movedTile, ts, tiles, ref currentMill);
            checkMill(10, 12, 15, movedTile, ts, tiles, ref currentMill);
            checkMill(13, 14, 15, movedTile, ts, tiles, ref currentMill);

            checkMill(16, 17, 18, movedTile, ts, tiles, ref currentMill);
            checkMill(16, 19, 21, movedTile, ts, tiles, ref currentMill);
            checkMill(18, 20, 23, movedTile, ts, tiles, ref currentMill);
            checkMill(21, 22, 23, movedTile, ts, tiles, ref currentMill);

            checkMill(1, 9, 17, movedTile, ts, tiles, ref currentMill);
            checkMill(3, 11, 19, movedTile, ts, tiles, ref currentMill);
            checkMill(4, 12, 20, movedTile, ts, tiles, ref currentMill);
            checkMill(6, 14, 22, movedTile, ts, tiles, ref currentMill);

            // Check validity
            if (currentMill == null) return false;
            currentMill.Turn = Turn;

            if (currentMill.First != movedTile &&
                currentMill.Second != movedTile &&
                currentMill.Third != movedTile)
                return false;

            // Check that he's not going back and forth from two mills
            if (PreviousMills.Count > 1 && currentMill.Equals(PreviousMills[PreviousMills.Count - 2]) && currentMill.Turn - PreviousMills[PreviousMills.Count - 2].Turn <= 2)
                return false;

            PreviousMills.Add(currentMill);

            return true;
        }