Exemple #1
0
        //
        // GET: /Board/

        public ActionResult Index(int?id)
        {
            if ((id ?? 0) == 0)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var board = ThreadedCommentsContext.Boards.SingleOrDefault(b => b.BoardId == id);

            if (board == null)
            {
                throw new Exception("No board with id = " + id);
            }

            var viewModel = new BoardIndex();

            viewModel.BoardId     = board.BoardId;
            viewModel.Name        = board.Name;
            viewModel.Description = board.Description;

            viewModel.Posts = ThreadedCommentsContext.Posts
                              .Where(p => p.BoardId == id)
                              .OrderByDescending(p => p.PostUtcDate)
                              .Take(50)
                              .ToList()
                              .Select(p => new BoardIndex.PostInfo {
                PostId = p.PostId, Title = p.Title, Body = p.Body, AuthorName = p.AuthorName, AuthorEmail = p.AuthorEmail, PostUtcDate = p.PostUtcDate
            })
                              .ToList();

            return(View(viewModel));
        }
        private List <BoardIndex> GetMovesForQueen(BoardIndex begin)
        {
            List <BoardIndex> possibleMoves = new List <BoardIndex>();

            for (int i = -1; i <= 1; i += 2)//for each direction
            {
                for (int j = -1; j <= 1; j += 2)
                {
                    int x = begin.Row + i;
                    int y = begin.Col + j;
                    while (board.IsInBound(x, y))
                    {
                        if (board[x, y] == null)
                        {
                            possibleMoves.Add(new BoardIndex(x, y));
                        }
                        else
                        {
                            break;
                        }
                        x += i;
                        y += j;
                    }
                }
            }
            return(possibleMoves);
        }
Exemple #3
0
 /// <summary>
 /// Check if the move is posible.
 /// </summary>
 /// <param name="StartPosition">Currnet position</param>
 /// <param name="EndPos">Wanted position</param>
 /// <returns></returns>
 private bool IsAdjacent(BoardIndex StartPosition, BoardIndex EndPosition)
 {
     if (MyPositions[(int)StartPosition].Up != null)
     {
         if (MyPositions[(int)StartPosition].Up.GetLocation() == EndPosition)
         {
             return(true);
         }
     }
     if (MyPositions[(int)StartPosition].Down != null)
     {
         if (MyPositions[(int)StartPosition].Down.GetLocation() == EndPosition)
         {
             return(true);
         }
     }
     if (MyPositions[(int)StartPosition].Left != null)
     {
         if (MyPositions[(int)StartPosition].Left.GetLocation() == EndPosition)
         {
             return(true);
         }
     }
     if (MyPositions[(int)StartPosition].Right != null)
     {
         if (MyPositions[(int)StartPosition].Right.GetLocation() == EndPosition)
         {
             return(true);
         }
     }
     return(false);
 }
 protected override void Awake()
 {
     base.Awake();
     levelIndex = 1;
     boardIndex = 0;
     gameState  = GameState.Start;
 }
Exemple #5
0
    /// <summary>
    /// 指定されたセルを塗る
    /// </summary>
    public void PaintCell(BoardIndex index, bool isMine)
    {
        if (isMine)
        {
            //赤いセルを浮上させる
            redCellObj[index.xIndex, index.yIndex].transform.position =
                new Vector3(redCellObj[index.xIndex, index.yIndex].transform.position.x,
                            1.005f,
                            redCellObj[index.xIndex, index.yIndex].transform.position.z);

            //青いセルを沈める
            blueCellObj[index.xIndex, index.yIndex].transform.position =
                new Vector3(blueCellObj[index.xIndex, index.yIndex].transform.position.x,
                            0.5f,
                            blueCellObj[index.xIndex, index.yIndex].transform.position.z);
        }
        else
        {
            //赤いセルを沈める
            redCellObj[index.xIndex, index.yIndex].transform.position =
                new Vector3(redCellObj[index.xIndex, index.yIndex].transform.position.x,
                            0.5f,
                            redCellObj[index.xIndex, index.yIndex].transform.position.z);

            //青いセルを浮上させる
            blueCellObj[index.xIndex, index.yIndex].transform.position =
                new Vector3(blueCellObj[index.xIndex, index.yIndex].transform.position.x,
                            1.005f,
                            blueCellObj[index.xIndex, index.yIndex].transform.position.z);
        }

        //ボード情報に登録する
        board.SetBoardColor(index, isMine);
    }
Exemple #6
0
    /// <summary>
    /// 盤面に相手の配置情報をマージする
    /// </summary>
    /// <param name="alignInfo"></param>
    private void MargeOpponentBoard(int[] alignInfo)
    {
        GameObject topPref = Resources.Load <GameObject>("GameObjects/BattleScene/Top");

        for (int i = 1; i < 6; i++)
        {
            if (alignInfo[i] == 0)
            {
                continue;
            }

            GameObject top = Instantiate(topPref);

            //マテリアル設定
            Material[] mats = top.GetComponent <MeshRenderer>().materials;
            mats[0] = Resources.Load <Material>("Materials/" + topTableList.Find(topTable => topTable.Id == alignInfo[i]).AssetName);
            top.GetComponent <MeshRenderer>().materials = mats;

            BattleTopCtrl topCtrl = top.GetComponent <BattleTopCtrl>();
            BoardIndex    index   = new BoardIndex((GameDef.BOARD_CELLS + 1) - i, 1);
            Vector2       tmpVec  = board.GetBoardPosByIndex(index);
            top.transform.position = new Vector3(tmpVec.x, 1, tmpVec.y);
            topCtrl.topId          = alignInfo[i];
            topCtrl.SetIsMine(false);
            topCtrl.SetIsMyTurn(false);
            board.SetBoardInf(alignInfo[i], top, false, index);
        }

        //初期位置は塗っておく
        for (int i = 1; i <= GameDef.BOARD_CELLS; i++)
        {
            BoardIndex index = new BoardIndex(i, 1);
            PaintCell(index, false);
        }
    }
Exemple #7
0
    /// <summary>
    /// コマを失う
    /// </summary>
    /// <param name="obj"></param>
    public void LostATop(GameObject obj)
    {
        int id = obj.GetComponent <BattleTopCtrl>().topId;

        //持ち駒リストに追加する
        for (int i = 1; i <= 3; i++)
        {
            for (int j = 1; j <= 3; j++)
            {
                BoardIndex index = new BoardIndex(j, i);
                //コマがなければそこに移動
                if (!opponentTopStage.ChkBoardTop(index))
                {
                    opponentTopStage.SetBoardInf(id, obj, false, index);
                    Vector2 tmpPos = opponentTopStage.GetBoardPosByIndexChild(index);

                    //オブジェクトを移動
                    obj.transform.position = new Vector3(tmpPos.x, 1, tmpPos.y);
                    obj.GetComponent <BattleTopCtrl>().SetIsMine(false);
                    obj.GetComponent <BattleTopCtrl>().SetIndex(index);
                    return;
                }
            }
        }
    }
Exemple #8
0
    /// <summary>
    /// コマを獲得する
    /// </summary>
    public void GetATop(GameObject obj)
    {
        int id = obj.GetComponent <BattleTopCtrl>().topId;

        //持ち駒リストに追加する
        for (int i = 3; i >= 1; i--)
        {
            for (int j = 3; j >= 1; j--)
            {
                BoardIndex index = new BoardIndex(j, i);
                //コマがなければそこに移動
                if (!myTopStage.ChkBoardTop(index))
                {
                    myTopStage.SetBoardInf(id, obj, true, index);
                    Vector2 tmpPos = myTopStage.GetBoardPosByIndexChild(index);

                    //オブジェクトを移動
                    obj.transform.position = new Vector3(tmpPos.x, 1, tmpPos.y);
                    obj.GetComponent <BattleTopCtrl>().SetIsMine(true);
                    obj.GetComponent <BattleTopCtrl>().SetIndex(index);
                    return;
                }
            }
        }
    }
Exemple #9
0
    /// <summary>
    /// float情報から移動情報に変換する
    /// </summary>
    /// <param name="inf"></param>
    /// <returns></returns>
    public TopMoveInf ConvSetMoveInf(float inf)
    {
        int destinationY = (int)(inf % 0x10);

        inf -= destinationY;
        inf /= 0x10;
        int destinationX = (int)(inf % 0x10);

        inf -= destinationX;
        inf /= 0x10;
        int sourceY = (int)(inf % 0x10);

        inf -= sourceY;
        inf /= 0x10;
        int sourceX = (int)(inf % 0x10);

        inf -= sourceX;
        inf /= 0x10;

        bool isBring;

        if (inf == 1)
        {
            isBring = true;
        }
        else
        {
            isBring = false;
        }
        BoardIndex source      = new BoardIndex(sourceX, sourceY);
        BoardIndex destination = new BoardIndex(destinationX, destinationY);

        return(new TopMoveInf(source, destination, isBring));
    }
        protected override List <BoardIndex> GetMovesInternal(Checker checker, BoardIndex begin, List <BoardIndex> moves)
        {
            Stack <Checker> checkersThatCanBeat = new Stack <Checker>();

            for (int i = 0; i < board.Rows; i++)
            {
                for (int j = 0; j < board.Cols; j++)
                {
                    Checker toTest = board[i, j];
                    if (toTest == null || toTest.PlayerType != checker.PlayerType)
                    {
                        continue;
                    }

                    var otherMoves = beatHandler.GetMoves(new BoardIndex(i, j));
                    if (otherMoves.Count > 0)
                    {
                        checkersThatCanBeat.Push(toTest);
                    }
                }
            }
            if (checkersThatCanBeat.Count == 0 || checkersThatCanBeat.Contains(checker))
            {
                return(Next?.GetMoves(begin, moves) ?? new List <BoardIndex>());
            }
            return(new List <BoardIndex>());
        }
Exemple #11
0
        /// <summary>
        /// Capture position
        /// </summary>
        /// <param name="Position">Index that we capture.</param>
        private void Capture(BoardIndex Position)
        {
            Player capturePlayer = MyPositions[(int)Position].Player;

            MyPositions[(int)Position].SetPlayer(Player.Neutral);
            MyPlaced[(int)capturePlayer]--;
        }
Exemple #12
0
        public async Task <BoardIndex> GetShot(string playerWebApiUrl, ISinglePlayerGame game, string?apiKey = null)
        {
            var client = httpClientFactory.GetHttpClient(playerWebApiUrl);
            var url    = BuildPathWithKey("getShot", apiKey);

            var shotRequest = new ShotRequest(game.LastShot, game.ShootingBoard.ToShortString());
            var request     = new HttpRequestMessage()
            {
                Method     = HttpMethod.Post,
                RequestUri = new Uri(url, UriKind.Relative)
            };

            request.Content = new StringContent(JsonSerializer.Serialize(shotRequest, jsonOptions), Encoding.UTF8, MediaTypeNames.Application.Json);

            var response = await client.SendAsync(request, getShotTimeout);

            var responseShotString = await response.Content.ReadFromJsonAsync <string>();

            if (string.IsNullOrEmpty(responseShotString))
            {
                throw new InvalidShotException(null, "Player returned no or empty shot");
            }
            if (!BoardIndex.TryParse(responseShotString, out var responseShot))
            {
                throw new InvalidShotException(responseShotString, "Player returned invalid shot");
            }

            return(responseShot);
        }
    /// <summary>
    /// ベクトル情報から最も近い盤面位置を出力する
    /// </summary>
    /// <param name="vec"></param>
    /// <returns></returns>
    public Vector2 GetCellPosByPos(Vector2 vec, ref BoardIndex index)
    {
        index = new BoardIndex(0, 0);
        float tmpVal = 0;

        for (int i = 1; i <= boardSize; i++)
        {
            if (i != 1 &&
                tmpVal < Mathf.Abs(vec.x - GetBoardPosByIndex(new BoardIndex(i, 1)).x))
            {
                break;
            }

            index.xIndex = i;
            tmpVal       = Mathf.Abs(vec.x - GetBoardPosByIndex(new BoardIndex(i, 1)).x);
        }

        tmpVal = 0;
        for (int i = 1; i <= boardSize; i++)
        {
            if (i != 1 &&
                tmpVal < Mathf.Abs(vec.y - GetBoardPosByIndex(new BoardIndex(1, i)).y))
            {
                break;
            }

            index.yIndex = i;
            tmpVal       = Mathf.Abs(vec.y - GetBoardPosByIndex(new BoardIndex(1, i)).y);
        }

        return(GetBoardPosByIndex(index));
    }
 private void MoveGate(BoardIndex obj)
 {
     if (obj.Equals(BoardIndex.First))
     {
         transform.DOMoveY(-0.35f, 1f);
     }
 }
Exemple #15
0
        public void Test_BeatHandler_ReturnsPossibleMovesCorrectly_WhenMoverIsQueen()
        {
            BoardIndex e3    = BoardIndex.Parse("e3");
            BoardIndex c5    = BoardIndex.Parse("c5");
            Checker    white = new Checker(PlayerType.White)
            {
                IsQueen = true
            };
            Checker black = new Checker(PlayerType.Black)
            {
                IsQueen = false
            };

            board[e3.Row, e3.Col] = white;
            board[c5.Row, c5.Col] = black;
            BeatHandler beatHandler = new BeatHandler(board);
            var         moves       = beatHandler.GetMoves(c5, new List <BoardIndex>()
            {
                e3
            });
            var expectedMoves = new List <BoardIndex>
            {
                BoardIndex.Parse("b6"),
                BoardIndex.Parse("a7")
            };

            Assert.AreEqual(expectedMoves, moves);
        }
Exemple #16
0
    /// <summary>
    /// 自分のターンを終了する
    /// </summary>
    /// <param name="source"></param>
    /// <param name="destination"></param>
    /// <param name="IsBring"></param>
    public void TurnEnd(BoardIndex source, BoardIndex destination, bool IsBring)
    {
        /* 自分のコマを非アクティブにする */
        List <BoardIndex> indexList = board.GetMyTopBoardIndex();

        foreach (BoardIndex index in indexList)
        {
            GameObject obj = board.GetObjByIndex(index);
            obj.GetComponent <BattleTopCtrl>().SetIsMyTurn(false);
        }

        //自分の持ち駒をすべてアクティブにする
        List <GameObject> objList = myTopStage.GetGameObjectAll();

        foreach (GameObject obj in objList)
        {
            obj.GetComponent <BattleTopCtrl>().SetIsMyTurn(false);
        }

        /* ターン情報通知 */
        TopMoveInf inf  = new TopMoveInf(source, destination, IsBring);
        float      move = ConvMoveInf(inf);

        Debug.Log(move);
        //自分のターンはここで終了
        turnManager.SendMove(move, true);
    }
Exemple #17
0
        public void TestBeatHandler_CannotBeatThroughtTheAlly()
        {
            BoardIndex g1    = BoardIndex.Parse("g1");
            BoardIndex e3    = BoardIndex.Parse("e3");
            BoardIndex c5    = BoardIndex.Parse("c5");
            Checker    white = new Checker(PlayerType.White)
            {
                IsQueen = true
            };
            Checker white2 = new Checker(PlayerType.White)
            {
                IsQueen = false
            };
            Checker black2 = new Checker(PlayerType.Black)
            {
                IsQueen = false
            };

            board[g1.Row, g1.Col] = white;
            board[e3.Row, e3.Col] = white2;
            board[c5.Row, c5.Col] = black2;
            BeatHandler beatHandler = new BeatHandler(board);
            var         moves       = beatHandler.GetMoves(g1, new List <BoardIndex> {
                g1
            });

            Assert.AreEqual(new List <BoardIndex>(), moves);
        }
Exemple #18
0
        public void Test_FirstMoveDoneHandler_ReturnMovesThatAllowsToBeat()
        {
            BoardIndex e3    = BoardIndex.Parse("e3");
            BoardIndex d4    = BoardIndex.Parse("d4");
            BoardIndex c5    = BoardIndex.Parse("c5");
            BoardIndex b6    = BoardIndex.Parse("b6");
            BoardIndex a7    = BoardIndex.Parse("a7");
            Checker    white = new Checker(PlayerType.White)
            {
                IsQueen = false
            };
            Checker black1 = new Checker(PlayerType.Black)
            {
                IsQueen = false
            };

            board[e3.Row, e3.Col] = white;
            board[d4.Row, d4.Col] = black1;
            board[b6.Row, b6.Col] = black1;
            FirstMoveDoneHandler firstMoveDoneHandler = new FirstMoveDoneHandler(board);
            var moves = firstMoveDoneHandler.GetMoves(c5, new List <BoardIndex> {
                e3, c5
            });

            Assert.AreEqual(new List <BoardIndex>()
            {
                a7
            }, moves);
        }
 private void SpawnConfetti(BoardIndex obj)
 {
     if (obj.Equals(BoardIndex.Second))
     {
         GameObject go = Instantiate(confettiPrefab, new Vector3(0, 0, 15), Quaternion.Euler(180f, 0, 0));
         Destroy(go, 2.5f);
     }
 }
 public void AddUserStone(BoardIndex index)
 {
     if (!Status.IsInGame() || !IsUserTurn)
     {
         return;
     }
     AddStone(index);
 }
Exemple #21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Move">Move object instance</param>
 public Move(Move Move)
 {
     this.StartPosition   = Move.StartPosition;
     this.EndPosition     = Move.EndPosition;
     this.CapturePosition = Move.CapturePosition;
     this.Type            = Move.Type;
     Move.OurMovesGenerated++;
 }
Exemple #22
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="Type">Current Type</param>
 /// <param name="StartPosition">Begin position</param>
 /// <param name="EndPosition">End reaction position</param>
 /// <param name="CapturePosition">End capture position</param>
 public Move(MoveType Type, BoardIndex StartPosition, BoardIndex EndPosition, BoardIndex CapturePosition)
 {
     this.Type            = Type;
     this.StartPosition   = StartPosition;
     this.EndPosition     = EndPosition;
     this.CapturePosition = CapturePosition;
     this.Init();
 }
    /// <summary>
    /// コマIDと現在地から移動可能領域のリストを出力する
    /// </summary>
    /// <param name="id"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    public List <BoardIndex> GetMovableIndex(int id, BoardIndex inputIndex)
    {
        List <BoardIndex> indexList   = new List <BoardIndex>();
        BoardIndex        originIndex = new BoardIndex(inputIndex.xIndex, inputIndex.yIndex);

        //浪人の場合はそのまま渡す
        if (id == 10)
        {
            return(topMovableDic[10]);
        }

        foreach (BoardIndex tmpIndex in topMovableDic[id])
        {
            BoardIndex index = new BoardIndex(tmpIndex.xIndex + inputIndex.xIndex, tmpIndex.yIndex + inputIndex.yIndex);

            //範囲外であれば移動不可
            if (index.xIndex > boardSize ||
                index.yIndex > boardSize ||
                index.xIndex <= 0 ||
                index.yIndex <= 0)
            {
                continue;
            }

            //味方のコマがあれば移動不可
            if (boardInf[index.xIndex, index.yIndex].topId != 0 &&
                boardInf[index.xIndex, index.yIndex].isMine == true)
            {
                continue;
            }

            //元の位置とを繋ぐ縦1本道上に敵、味方のコマがあれば移動不可
            //id = 9(狙撃手は縦一本道上に敵味方がいても関係なく移動可)
            if (ChkAnotherTopColumn(index, originIndex) &&
                id != 9)
            {
                continue;
            }

            //元の位置とを繋ぐ横1本道上に敵、味方のコマがあれば移動不可
            if (ChkAnotherTopRow(index, originIndex))
            {
                continue;
            }

            //元の位置とを繋ぐ斜め1本道上に敵、味方のコマがあれば移動不可
            if (ChkAnotherTopDiago(index, originIndex))
            {
                continue;
            }

            //移動可能なのでリストに追加する
            indexList.Add(index);
        }

        return(indexList);
    }
        public void Test_ParseReturnsSameBoardIndex([Values(0, 1, 2, 3, 4, 5, 6, 7)] int x, [Values(0, 1, 2, 3, 4, 5, 6, 7)] int y)
        {
            var    index = new BoardIndex(x, y);
            string str   = index.ToString();
            var    res   = BoardIndex.Parse(str);

            Assert.AreEqual(index.Row, res.Row);
            Assert.AreEqual(index.Col, res.Col);
        }
        protected override List <BoardIndex> GetMovesInternal(Checker checker, BoardIndex begin, List <BoardIndex> moves)
        {
            List <BoardIndex> beatMoves = new List <BoardIndex>();

            for (int i = -1; i <= 1; i += 2)//for each direction
            {
                for (int j = -1; j <= 1; j += 2)
                {
                    bool stopMovingInCurrentDirection = false;
                    int  x = begin.Row + i;
                    int  y = begin.Col + j;
                    while (board.IsInBound(x, y))
                    {
                        if (CanBeat(checker, begin, new BoardIndex(x, y)))
                        {
                            if (!checker.IsQueen)
                            {
                                beatMoves.Add(new BoardIndex(begin.Row + i * 2, begin.Col + j * 2));
                            }
                            else
                            {
                                int xq = x + i;
                                int yq = y + j;
                                while (board.IsInBound(xq, yq))
                                {
                                    if (board[xq, yq] == null)
                                    {
                                        beatMoves.Add(new BoardIndex(xq, yq));
                                    }
                                    else
                                    {
                                        stopMovingInCurrentDirection = true;
                                        break;
                                    }
                                    xq += i;
                                    yq += j;
                                }
                            }
                        }
                        else if (stopMovingInCurrentDirection || (board[x, y] != null && board[x, y].PlayerType == checker.PlayerType))
                        {
                            break;
                        }
                        x += i;
                        y += j;
                    }
                }
            }

            if (beatMoves.Count > 0)
            {
                return(beatMoves);
            }

            return(Next?.GetMoves(begin, moves) ?? new List <BoardIndex>());
        }
Exemple #26
0
        /// <summary>
        /// Is mill possible
        /// </summary>
        /// <param name="Position">For current position</param>
        /// <param name="Player">Current player</param>
        /// <returns>Is possible mill</returns>
        private bool IsMill(BoardIndex Position, Player Player)
        {
            // Active vertical
            if (IsVerticalMill(Position, Player))
            {
                return(true);
            }

            // Active horizontal
            return(IsHorizontalMill(Position, Player));
        }
 /// <summary>
 /// ボードに色をつける
 /// </summary>
 /// <param name="index"></param>
 /// <param name="IsMine"></param>
 public void SetBoardColor(BoardIndex index, bool IsMine)
 {
     if (IsMine)
     {
         boardInf[index.xIndex, index.yIndex].colorInf = 1;
     }
     else
     {
         boardInf[index.xIndex, index.yIndex].colorInf = 2;
     }
 }
        private IEnumerable <BoardIndex> GetIndexEnumerable(BoardIndex index, IndexDirection direction)
        {
            var ary = new BoardIndex[Setting.ConnectCount];

            foreach (var ii in Enumerable.Range(0, Setting.ConnectCount))
            {
                ary[ii] = index;
                index   = index.GetIndex(direction);
            }
            return(ary);
        }
Exemple #29
0
        /// <inheritdoc />
        public override async Task GetShot(Guid gameId, string __, IReadOnlyBoard board, Shoot shoot)
        {
            if (!indexes.TryGetValue(gameId, out BoardIndex ix))
            {
                ix = indexes[gameId] = new BoardIndex();
            }

            // Shoot at first current square
            await shoot(ix);

            indexes[gameId]++;
        }
    public Vector2 GetBoardPosByIndexChild(BoardIndex index)
    {
        Vector2 cellPos = new Vector2(0, 0);

        //将棋盤の右上を原点にする
        cellPos = boardPos + new Vector2(0.5f, 0.5f);

        cellPos = new Vector2(cellPos.x - (float)(2 * index.xIndex - 1) / (2 * boardSize),
                              cellPos.y - (float)(2 * index.yIndex - 1) / (2 * boardSize));

        return(cellPos);
    }