// Start is called before the first frame update

    public void Spawn()
    {
        int amtObj = 0;

        switch (type)
        {
        case PieceType.jump:
            amtObj = levelManager.Instance.jumps.Count;
            break;

        case PieceType.slide:
            amtObj = levelManager.Instance.slides.Count;
            break;

        case PieceType.longBlock:
            amtObj = levelManager.Instance.longBlocks.Count;
            break;

        case PieceType.ramp:
            amtObj = levelManager.Instance.ramps.Count;
            break;
        }
        currentPiece = levelManager.Instance.GetPiece(type, Random.Range(0, amtObj));
        currentPiece.gameObject.SetActive(true);
        currentPiece.transform.SetParent(transform, false);
    }
Exemple #2
0
        public string ToString(int i, int n)
        {
            if ((i == 0 && n == len && pCnt > 1) || pCnt > pCntThresh)
            {
                string sa = ToString();
                Reset(sa);
            }
            sb.Clear();
            Seek(i);
            piece p  = phyP;
            int   pi = phyI;

            while (n > 0)
            {
                int loc  = p.loc + pi;
                int take = Math.Min(p.len - pi, n);
                sb.Append(p.old ? oldTxt.Substring(loc, take) : newTxt.ToString(loc, take));
                n -= take;
                if (n > 0)
                {
                    p = p.nxt;
                    if (p == tail)
                    {
                        throw new ssException("raw tostring range");
                    }
                    pi = 0;
                }
            }
            return(sb.ToString());
        }
Exemple #3
0
    public bool IsWin(piece _piece)
    {
        foreach (var castle in castles)
        {
            if (_piece.team_number != castle.team_num)
            {
                Vector2 rev = castle.sell + (castle.sell - _piece.sell);
                Debug.Log(rev);

                if (GamaManager.Instance.Board.getSellDate(rev).on_pise != null)
                {
                    if (GamaManager.Instance.Board.getSellDate(rev).on_pise.is_siege)
                    {
                        return(true);
                    }
                }



                //Vector2 rev = castle.sell-(_piece.sell - castle.sell);
                //if (GamaManager.Instance.Board.getSellDate(rev).)
                return(false);
            }
        }
        return(false);
    }
Exemple #4
0
    int gimmeValue(piece p)
    {
        switch (p)
        {
        case piece.Bishop:
            return(3);

        case piece.Rook:
            return(5);

        case piece.Knight:
            return(3);

        case piece.King:
            return(1000);

        case piece.Pawn:
            return(1);

        case piece.Queen:
            return(9);

        default:
            return(0);
        }
    }
Exemple #5
0
    private void SelectPiece(int x, int y)
    {
        if (x < 0 || x >= 8 || y < 0 || y >= 8)
        {
            return;
        }

        piece p = pieces[x, y];

        if (p != null && p.isWhite == isWhite)
        {
            if (forcedPieces.Count == 0)
            {
                selectedPiece = p;
                startDrag     = moseOver;
            }
            else
            {
                if (forcedPieces.Find(fp => fp == p) == null)
                {
                    return;
                }

                selectedPiece = p;
                startDrag     = moseOver;
            }
        }
    }
Exemple #6
0
 //movePiece function that accepts a piece, an int array, and the 2d board array
 //the function returns the same piece that is accepted with the row and col updated to the newPos
 //the board is then updated with the new piece position
 static piece movePiece(piece temp, int[] newPos, int[,] board)
 {
     board[temp.row, temp.col] = 0;
     temp.col = newPos[1];
     temp.row = newPos[0];
     if (temp.king)
     {
         if (temp.red)
         {
             board[newPos[0], newPos[1]] = 3;
         }
         else
         {
             board[newPos[0], newPos[1]] = 4;
         }
     }
     else
     {
         if (temp.red)
         {
             board[newPos[0], newPos[1]] = 1;
         }
         else
         {
             board[newPos[0], newPos[1]] = 2;
         }
     }
     return(temp);
 }
Exemple #7
0
    public piece GetPiece(PieceType pt, int visualIndex)

    {
        piece p = pieces.Find(x => x.type == pt && x.visualIndex == visualIndex && !x.gameObject.activeSelf);

        if (p == null)
        {
            GameObject go = null;
            if (pt == PieceType.ramp)
            {
                go = ramps[visualIndex].gameObject;
            }
            else if (pt == PieceType.longBlock)
            {
                go = longBlocks[visualIndex].gameObject;
            }
            else if (pt == PieceType.jump)
            {
                go = jumps[visualIndex].gameObject;
            }
            else if (pt == PieceType.slide)
            {
                go = slides[visualIndex].gameObject;
            }

            go = Instantiate(go);
            p  = go.GetComponent <piece>();
        }
        return(p);
    }
 public void moveLeft(ref piece selectedPiece, ref ConsoleKey currentAltitudeKey, ref game currentGame)
 {
     if (selectedPiece != null)
     {
         if (selectedPiece.king)
         {
             if (currentAltitudeKey == ConsoleKey.UpArrow)
             {
                 selectedPiece.move(new int[] { -1, -1 }, currentGame.gameMap);
             }
             else if (currentAltitudeKey == ConsoleKey.DownArrow)
             {
                 selectedPiece.move(new int[] { -1, 1 }, currentGame.gameMap);
             }
             currentAltitudeKey = new ConsoleKey();
         }
         else
         {
             if (selectedPiece.value == map.player1)
             {
                 selectedPiece.move(new int[] { -1, 1 }, currentGame.gameMap);
             }
             else if (selectedPiece.value == map.player2)
             {
                 selectedPiece.move(new int[] { -1, -1 }, currentGame.gameMap);
             }
         }
         selectedPiece = null;
     }
     else
     {
         currentGame.gameMap.move(new int[] { -1, 0 });
     }
 }
 public void addinstance()
 {
     tile[]  tiles  = new tile[64];
     piece[] pieces = new piece[32];
     for (int i = 0; i < 64; i++)
     {
         GameObject x = chessboard.GetComponent <chessboard> ().tiles [i];
         tiles [i].a   = x;
         tiles [i].top = x.GetComponent <tileprops> ().top;
     }
     for (int i = 0; i < 32; i++)
     {
         GameObject x = chessboard.GetComponent <chessboard> ().pieces [i];
         pieces [i].a = x;
         if (x != null)
         {
             pieces [i].tile      = x.GetComponent <chesspiece> ().tile;
             pieces [i].tem       = x.transform.position;
             pieces [i].row       = x.GetComponent <chesspiece> ().row;
             pieces [i].col       = x.GetComponent <chesspiece> ().col;
             pieces [i].movecount = x.GetComponent <chesspiece> ().movecount;
             pieces [i].ptype     = x.GetComponent <chesspiece> ().ptype;
             pieces [i].pcolor    = x.GetComponent <chesspiece> ().pcolour;
             pieces [i].wkilled   = x.GetComponent <chesspiece> ().tile.GetComponent <tileprops> ().killmove;
             if (pieces [i].wkilled == true)
             {
                 Debug.Log("As");
             }
         }
     }
     boardinstances.Add(tiles);
     pieceinstance.Add(pieces);
     movecount++;
 }
Exemple #10
0
    void generateRook(int i, int j, bool Queen)
    {
        piece p = piece.Rook;

        if (Queen)
        {
            p = piece.Queen;
        }

        for (int x = 1;; x++)
        {
            if (board [i + x, j].pieceSquare == piece.OutOfBoard)
            {
                break;
            }
            attacks [i + x, j, i, j] = p;
            if (board [i + x, j].pieceSquare != piece.None)
            {
                break;
            }
        }
        for (int x = 1;; x++)
        {
            if (board [i, j + x].pieceSquare == piece.OutOfBoard)
            {
                break;
            }
            attacks [i, j + x, i, j] = p;
            if (board [i, j + x].pieceSquare != piece.None)
            {
                break;
            }
        }
        for (int x = 1;; x++)
        {
            if (board [i, j - x].pieceSquare == piece.OutOfBoard)
            {
                break;
            }
            attacks [i, j - x, i, j] = p;
            if (board [i, j - x].pieceSquare != piece.None)
            {
                break;
            }
        }
        for (int x = 1;; x++)
        {
            if (board [i - x, j].pieceSquare == piece.OutOfBoard)
            {
                break;
            }
            attacks [i - x, j, i, j] = p;
            if (board [i - x, j].pieceSquare != piece.None)
            {
                break;
            }
        }
    }
Exemple #11
0
    //実際に全体攻撃する関数
    //攻撃可能マスに攻撃を与える関数
    public void AllAttack(piece _terget_piese)
    {
        List <piece> anger = new List <piece>();

        foreach (var _line in map)
        {
            foreach (var _sell in _line)
            {
                if (_sell.is_attack)
                {
                    if (_sell.on_pise != null)
                    {
                        if (_terget_piese.
                            team_number !=
                            _sell.on_pise.team_number)
                        {
                            _sell.on_pise.damage(
                                _terget_piese.attack_power);
                            if (_sell.on_pise != null)
                            {
                                anger.Add(_sell.on_pise);
                            }
                        }
                    }
                }
            }
        }
        allAttackOff();
        //反撃の処理
        foreach (var ang in anger)
        {
            ang.OnAttackArea(ang.sell);
            foreach (var _line in map)
            {
                foreach (var _sell in _line)
                {
                    if (_sell.is_attack)
                    {
                        if (_sell.on_pise != null)
                        {
                            if (ang.team_number !=
                                _sell.on_pise.team_number)
                            {
                                if (_sell.on_pise == _terget_piese)
                                {
                                    if (ang.life > 0)
                                    {
                                        _sell.on_pise.damage(ang.counter_attack_power);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            allAttackOff();
        }
    }
Exemple #12
0
    public void Cancel()
    {
        GamaManager.Instance.Board.allMovableOff();
        GamaManager.Instance.Board.allAttackOff();
        select_pieces = null;
        step          = 0;

        GamaManager.Instance.command_list.ALLSetInteractable(false);
    }
Exemple #13
0
 void paintPiece(int i, int j, piece p, side s)
 {
     if (s == side.Black)
     {
         if (p == piece.Bishop)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = BlackBishop;
         }
         if (p == piece.Queen)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = BlackQueen;
         }
         if (p == piece.King)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = BlackKing;
         }
         if (p == piece.Knight)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = BlackKnight;
         }
         if (p == piece.Pawn)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = BlackPawn;
         }
         if (p == piece.Rook)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = BlackRook;
         }
     }
     if (s == side.White)
     {
         if (p == piece.Bishop)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = WhiteBishop;
         }
         if (p == piece.Queen)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = WhiteQueen;
         }
         if (p == piece.King)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = WhiteKing;
         }
         if (p == piece.Knight)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = WhiteKnight;
         }
         if (p == piece.Pawn)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = WhitePawn;
         }
         if (p == piece.Rook)
         {
             board[i, j].obj.GetComponent <Renderer>().material.mainTexture = WhiteRook;
         }
     }
 }
Exemple #14
0
    private void UpdatePieceDrag(piece p)
    {
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 25.0f, LayerMask.GetMask("Board")))
        {
            p.transform.position = hit.point + Vector3.up;
        }
    }
Exemple #15
0
 public void setUiStatus(piece _piece)
 {
     select_status.text =
         "status\n" +
         "体力  " + _piece.life + " / " + _piece.max_hp + "\n" +
         "攻撃力 " + _piece.attack_power + "\n" +
         "反撃力 " + _piece.counter_attack_power + "\n"
     ;
 }
    static void Main(string[] Args)
    {
        game           currentGame        = new game();
        ConsoleKeyInfo currentKey         = new ConsoleKeyInfo();
        ConsoleKey     currentAltitudeKey = new ConsoleKey();
        piece          selectedPiece      = null;

        while (!currentGame.gameOver)
        {
            currentGame.draw();
            Console.WriteLine(currentGame.gameMap.player1Turn ? "White's Turn" : "Red's Turn");
            currentKey = Console.ReadKey();
            switch (currentKey.Key)
            {
            case ConsoleKey.LeftArrow:
                currentGame.gameMap.moveLeft(ref selectedPiece, ref currentAltitudeKey, ref currentGame);
                break;

            case ConsoleKey.RightArrow:
                currentGame.gameMap.moveRight(ref selectedPiece, ref currentAltitudeKey, ref currentGame);
                break;

            case ConsoleKey.UpArrow:
                currentGame.gameMap.moveUp(ref selectedPiece, ref currentAltitudeKey, ref currentGame);
                break;

            case ConsoleKey.DownArrow:
                currentGame.gameMap.moveDown(ref selectedPiece, ref currentAltitudeKey, ref currentGame);
                break;

            case ConsoleKey.Escape:
                if (selectedPiece != null)
                {
                    selectedPiece = null;
                }
                else
                {
                    currentGame.gameOver = true;
                }
                break;

            case ConsoleKey.Spacebar:
                selectedPiece = currentGame.gameMap.findPiece(new int[] { currentGame.gameMap.getPos()[1], currentGame.gameMap.getPos()[0] });
                if (selectedPiece != null)
                {
                    if ((selectedPiece.value != map.player1) == currentGame.gameMap.player1Turn)
                    {
                        selectedPiece = null;
                    }
                }
                break;
            }
        }
        Console.BackgroundColor = ConsoleColor.Black;
        Console.Clear();
    }
Exemple #17
0
 public override void setMoveOn(piece _piece, CreateBoard board)
 {
     for (int i = 1; i <= length; i++)
     {
         if (!board.setMovable(_piece.sell + (go_sell * i)))
         {
             break;
         }
     }
 }
Exemple #18
0
        public Bishop(piece p, color c)
            : base(p, c)
        {
            base.Uri = c == color.eWhite ?
                       new Uri(@"../Chess/Resources/Bishop.png", UriKind.Relative) :
                       new Uri(@"../Chess/Resources/BishopB.png", UriKind.Relative);

            Img        = new Image();
            Img.Source = new BitmapImage(Uri);
        }
Exemple #19
0
 public override void SetAttackOn(piece _piece, Vector2 _sell)
 {
     for (int i = 1; i <= length; i++)
     {
         if (!GamaManager.Instance.Board.setIsAttack(_sell + (go_sell * i),
                                                     _piece.team_number))
         {
             return;
         }
     }
 }
Exemple #20
0
 public void enableScripts()
 {
     foreach (Transform pieceTransform in transform)
     {
         piece script = pieceTransform.gameObject.GetComponent <piece>();
         if (script != null)
         {
             script.enabled = true;
         }
     }
 }
Exemple #21
0
    private void GeneratePiece(int x, int y)
    {
        bool       isWhite = (y > 3) ? false : true;
        GameObject go      = Instantiate((isWhite) ? whitePiece : blackPiece) as GameObject;

        go.transform.SetParent(transform);
        piece p = go.GetComponent <piece>();

        pieces[x, y] = p;
        movePiece(p, x, y);
    }
 public void moveUp(ref piece selectedPiece, ref ConsoleKey currentAltitudeKey, ref game currentGame)
 {
     if (selectedPiece != null)
     {
         currentAltitudeKey = ConsoleKey.UpArrow;
     }
     else
     {
         currentGame.gameMap.move(new int[] { 0, -1 });
     }
 }
Exemple #23
0
    private List <piece> ScanForPossibleMove(piece p, int x, int y)
    {
        forcedPieces = new List <piece>();

        if (pieces[x, y].IsForceToMove(pieces, x, y))
        {
            forcedPieces.Add(pieces[x, y]);
        }

        return(forcedPieces);
    }
Exemple #24
0
 void InsPiece(piece p)   // Inserts after phyP
 {
     p.nxt    = phyP.nxt;
     p.prv    = phyP;
     phyP.nxt = p;
     if (p.nxt != null)
     {
         p.nxt.prv = p;
     }
     pCnt++;
 }
Exemple #25
0
    public void CreatePiece(PieceNum _piece, int x, int y, int _team)
    {
        GameObject obj = Instantiate(pieces[(int)_piece]);
        piece      pic = obj.GetComponent <piece>();

        pic.setSell(new Vector2(x, y));
        pic.team_number = _team;
        if (_team == 1)
        {
            obj.GetComponent <Renderer>().material.color = new Color(0, 1, 0);
        }
    }
Exemple #26
0
 public override void setMoveOn(piece _piece)
 {
     for (int i = 1; i <= length; i++)
     {
         if (!GamaManager.Instance.Board.setMovable(
                 _piece.sell + (go_sell * i),
                 _piece.team_number))
         {
             return;
         }
     }
 }
Exemple #27
0
    public bool ValidMove(piece[,] board, int x1, int y1, int x2, int y2)
    {
        if (board[x2, y2] != null)
        {
            return(false);
        }
        int deltaMove  = Mathf.Abs(x1 - x2);
        int deltaMoveY = y2 - y1;

        if (isWhite || isKing)
        {
            if (deltaMove == 1)
            {
                if (deltaMoveY == 1)
                {
                    return(true);
                }
            }
            else if (deltaMove == 2)
            {
                if (deltaMoveY == 2)
                {
                    piece p = board[(x1 + x2) / 2, (y1 + y2) / 2];
                    if (p != null && p.isWhite != isWhite)
                    {
                        return(true);
                    }
                }
            }
        }
        if (!isWhite || isKing)
        {
            if (deltaMove == 1)
            {
                if (deltaMoveY == -1)
                {
                    return(true);
                }
            }
            else if (deltaMove == 2)
            {
                if (deltaMoveY == -2)
                {
                    piece p = board[(x1 + x2) / 2, (y1 + y2) / 2];
                    if (p != null && p.isWhite != isWhite)
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Exemple #28
0
    public void CreatePiece(PieceNum _piece, int x, int y, int _team)
    {
        GameObject obj = Instantiate(pieces[(int)_piece]);
        piece      pic = obj.GetComponent <piece>();

        pic.setSell(new Vector2(x, y));
        pic.team_number = _team;
        pic.piece_num   = _piece;
        if (_team == 1)
        {
            obj.GetComponent <Renderer>().material.color = new Color(0, 1, 0);
        }
        if (PieceNum.KING == _piece)
        {
            GamaManager.Instance.kings_info.kings.Add(pic);
        }
    }
Exemple #29
0
        public string ToString()
        {
            StringBuilder sbb = new StringBuilder();

            for (piece p = head.nxt; p != tail; p = p.nxt)
            {
                if (p.old)
                {
                    sbb.Append(oldTxt.Substring(p.loc, p.len));
                }
                else
                {
                    sbb.Append(newTxt.ToString(p.loc, p.len));
                }
            }
            return(sbb.ToString());
        }
        piece ppd; // main parallelepiped

        #endregion Fields

        #region Methods

        public void init()
        {
            // init rotations
            rot[0] = new int[6] { 0, 1, 2, 3, 4, 5 }; dimRot[0] = new int[3] { 0, 1, 2 };
            rot[1] = new int[6] { 0, 1, 4, 5, 3, 2 }; dimRot[1] = new int[3] { 0, 2, 1 };
            rot[2] = new int[6] { 0, 1, 3, 2, 5, 4 }; dimRot[2] = new int[3] { 0, 1, 2 };
            rot[3] = new int[6] { 0, 1, 5, 4, 2, 3 }; dimRot[3] = new int[3] { 0, 2, 1 };

            rot[4] = new int[6] { 3, 2, 0, 1, 4, 5 }; dimRot[4] = new int[3] { 1, 0, 2 };
            rot[5] = new int[6] { 3, 2, 4, 5, 1, 0 }; dimRot[5] = new int[3] { 1, 2, 0 };
            rot[6] = new int[6] { 3, 2, 1, 0, 5, 4 }; dimRot[6] = new int[3] { 1, 0, 2 };
            rot[7] = new int[6] { 3, 2, 5, 4, 0, 1 }; dimRot[7] = new int[3] { 1, 2, 0 };

            rot[8] = new int[6] { 1, 0, 3, 2, 4, 5 }; dimRot[8] = new int[3] { 0, 1, 2 };
            rot[9] = new int[6] { 1, 0, 4, 5, 2, 3 }; dimRot[9] = new int[3] { 0, 2, 1 };
            rot[10] = new int[6] { 1, 0, 2, 3, 5, 4 }; dimRot[10] = new int[3] { 0, 1, 2 };
            rot[11] = new int[6] { 1, 0, 5, 4, 3, 2 }; dimRot[11] = new int[3] { 0, 2, 1 };

            rot[12] = new int[6] { 2, 3, 1, 0, 4, 5 }; dimRot[12] = new int[3] { 1, 0, 2 };
            rot[13] = new int[6] { 2, 3, 4, 5, 0, 1 }; dimRot[13] = new int[3] { 1, 2, 0 };
            rot[14] = new int[6] { 2, 3, 0, 1, 5, 4 }; dimRot[14] = new int[3] { 1, 0, 2 };
            rot[15] = new int[6] { 2, 3, 5, 4, 1, 0 }; dimRot[15] = new int[3] { 1, 2, 0 };

            rot[16] = new int[6] { 4, 5, 2, 3, 1, 0 }; dimRot[16] = new int[3] { 2, 1, 0 };
            rot[17] = new int[6] { 4, 5, 1, 0, 3, 2 }; dimRot[17] = new int[3] { 2, 0, 1 };
            rot[18] = new int[6] { 4, 5, 3, 2, 0, 1 }; dimRot[18] = new int[3] { 2, 1, 0 };
            rot[19] = new int[6] { 4, 5, 0, 1, 2, 3 }; dimRot[19] = new int[3] { 2, 0, 1 };

            rot[20] = new int[6] { 5, 4, 0, 1, 3, 2 }; dimRot[20] = new int[3] { 2, 0, 1 };
            rot[21] = new int[6] { 5, 4, 3, 2, 1, 0 }; dimRot[21] = new int[3] { 2, 1, 0 };
            rot[22] = new int[6] { 5, 4, 1, 0, 2, 3 }; dimRot[22] = new int[3] { 2, 0, 1 };
            rot[23] = new int[6] { 5, 4, 2, 3, 0, 1 }; dimRot[23] = new int[3] { 2, 1, 0 };

            // init vars
            string[] tok = readString();
            ppd = new piece(int.Parse(tok[0]), int.Parse(tok[1]), int.Parse(tok[2]), tok[3]);
            tok = readString();
            n = int.Parse(tok[0]);
            p = new piece[n];
            for (int i = 0; i < n; ++i)
            {
                tok = readString();
                p[i] = new piece(int.Parse(tok[0]), int.Parse(tok[1]), int.Parse(tok[2]), tok[3]);
            }
        }
Exemple #31
0
        public void Remove(int i, int len)
        {
            Seek(i + len);
            piece tp  = phyP;
            int   tpi = phyI;

            Seek(i);
            piece hp  = phyP;
            int   hpi = phyI;

            if (hp != tp)
            {
                hp.len -= (hp.len - hpi);
                if (hp.len == 0)
                {
                    hp = hp.prv;
                }
                tp.loc  = tp.loc + tpi;
                tp.len -= tpi;
                if (tp.len == 0)
                {
                    tp = tp.nxt;
                }
                hp.nxt = tp;
                tp.prv = hp;
                phyP   = tp;
                phyI   = 0;
                logI   = i;
            }
            else
            {
                piece np = new piece();
                np.old = hp.old;
                np.loc = hp.loc + hpi + len;
                np.len = hp.len - hpi - len;
                hp.len = hpi;

                InsPiece(np);

                phyP = np;
                phyI = 0;
                logI = i;
            }
            this.len -= len;
        }
 /// <summary>
 /// Makes a copy of the current board
 /// </summary>
 /// <returns></returns>
 piece[,] copyBoard()
 {
     piece[,] temp = new piece[6, 6];
     for (int i = 0; i < board.GetLength(0); i++)
     {
         for (int j = 0; j < board.GetLength(1); j++)
         {
             piece tempPiece = new piece();
             tempPiece.value = board[i,j].value;
             temp[i, j] = tempPiece;
         }
     }
     return temp;
 }
    /// <summary>
    /// checks if a winning line of pieces has been made
    /// </summary>
    /// <param name="winValue">Which value of piece to use for the check</param>
    /// <param name="winStreak">The amount of pieces we have in a line already, should be 0 when this isn't called by itself</param>
    /// <param name="row">the horizontal line to check</param>
    /// <param name="col">the vertical line to check</param>
    /// <param name="direction">a vec2 of where to check the next piece in the winning row</param>
    /// <returns></returns>
    int checkWin(int winValue, int winStreak, int row, int col, Vector2 direction, piece[,] tempBoard)
    {
        //Debug.Log(winStreak);
        if (winStreak == 4)
        {
            return 1;
        }
        else if (row < 0 || row >= board.GetLength(0) || col < 0 || col >= board.GetLength(1))
        {
            return 0;
        }

        if (!board[row, col].visited && winValue == board[row, col].value)
        {
            board[row, col].visited = true;
            int returnValue = checkWin(winValue, winStreak + 1, row + (int)direction.x, col + (int)direction.y, direction, board);
            board[row, col].visited = false;

            return returnValue;
        }

        return 0;
    }
    //Receive column and the player value
    //Go to column and look at
    void AddPiece(int column, int player, piece[,] tempBoard)
    {
        int i;

        if (boardState == 0)
        {
            for (i = 0; i < tempBoard.GetLength(0); i++)
            {
                if (tempBoard[column, i].value != 0)
                {
                    break;
                }
            }

            if (i == 0)
            {
                return;
            }
            i--;
        }
        else if (boardState == 1)
        {
            column = tempBoard.GetLength(1) - column - 1;
            for (i = 0; i < tempBoard.GetLength(0); i++)
            {
                if (tempBoard[i, column].value != 0)
                {
                    break;
                }
            }

            if (i == 0)
            {
                return;
            }

            int temp = i;
            i = column;
            column = temp;
            column--;
        }
        else if (boardState == 2)
        {
            column = tempBoard.GetLength(0) - column - 1;
            for (i = tempBoard.GetLength(0) - 1; i >= 0; i--)
            {
                if (tempBoard[column, i].value != 0)
                {
                    break;
                }
            }

            if (i == tempBoard.GetLength(0) - 1)
            {
                return;
            }

            i++;
        }
        else
        {
            for (i = tempBoard.GetLength(0) - 1; i >= 0; i--)
            {
                if (tempBoard[i, column].value != 0)
                {
                    break;
                }
            }

            if (i == tempBoard.GetLength(0) - 1)
            {
                return;
            }

            int temp = i;
            i = column;
            column = temp;
            column++;
        }

        tempBoard[column, i].value = player;

        int numWins = 0;

        numWins += checkWin(player, 0, column, i, new Vector2(1, -1), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(1, 0), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(1, 1), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(0, -1), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(0, 1), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(-1, -1), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(-1, 0), tempBoard);
        numWins += checkWin(player, 0, column, i, new Vector2(-1, 1), tempBoard);

        //Debug.Log("Check for wins");
        if (numWins > 0)
        {
            Debug.Log(player + " wins");
            if(player == 1)
            {
                gameEnd(1, 0);
            }
            else{
                gameEnd(0, 1);
            }
        }
        switchPlayers();
    }
Exemple #35
0
 public void SetBelow(piece value)
 {
     below = value;
 }
Exemple #36
0
 // Use this for initialization
 void Start()
 {
     value = 0;
     below = null;
     left = null;
     right = null;
     top = null;
 }
Exemple #37
0
 public void SetRight(piece value)
 {
     right = value;
 }
Exemple #38
0
 public void SetTop(piece value)
 {
     top = value;
 }
Exemple #39
0
 public void SetLeft(piece value)
 {
     left = value;
 }
 piece rotatePiece(piece t, int rotNumb)
 {
     piece res = new piece(t.dim[dimRot[rotNumb][0]],
             t.dim[dimRot[rotNumb][1]],
             t.dim[dimRot[rotNumb][2]],
             rotateCol(t.col, rotNumb));
     res.rotNumb = rotNumb;
     return res;
 }