void SelectType()
 {
     if (curSelectingType != StoneType.None && Input.GetKeyDown(KeyCode.Mouse0))
     {
         curSelectionType = curSelectingType;
     }
 }
Пример #2
0
 public StonePoint(int x, int y, StoneType stoneType = StoneType.黑子, int stepNum = 0)
 {
     this.PointX = x;
     this.PointY = y;
     this.Type = stoneType;
     this.StepNum = stepNum;
 }
Пример #3
0
    private void NextTurn()
    {
        ResetMovePosition();
        CheckWin();
        if (CurrentGameState == GameState.GAME_END)
        {
            return;
        }

        isWhiteTurn  = !isWhiteTurn;
        currentStone = StoneType.Flat;
        HighlightController.Instance.HideHighlights();

        foreach (Player p in players)
        {
            p.SwapColor();
        }

        if (Client.Instance)
        {
            if (isWhiteTurn == IsWhite)
            {
                CurrentGameState = GameState.TURN_START;
            }
            else
            {
                CurrentGameState = GameState.OPPONENTS_TURN;
            }
        }
        else
        {
            IsWhite          = !IsWhite;
            CurrentGameState = GameState.TURN_START;
        }
    }
Пример #4
0
        public void Update()
        {
            var game = service.GetGame();

            CurrentPlayer = game.CurrentTurn;

            Players.Clear();
            var map = game.CountStones();

            foreach (var pair in map)
            {
                Players.Add(new PlayerViewModel()
                {
                    StoneType = pair.Key, StoneCount = pair.Value, IsCurrentTurn = (pair.Key == CurrentPlayer)
                });
            }

            if (game.IsEnd)
            {
                if (ShowResult != null)
                {
                    var max    = map.Max(x => x.Value);
                    var winner = map.Where(x => x.Value == max).Select(y => y.Key);
                    ShowResult(winner.ToList());
                }
            }
        }
 public int CountStone(StoneType type, bool includingUsed = false)
 {
     if (includingUsed)
     {
         return(stones.Cnt((x) => x.type == type));
     }
     return(unusedStones.Cnt((x) => x.type == type));
 }
Пример #6
0
 public static StoneNetwork Create(StoneType stoneType, Vector3 position, Quaternion rotation)
 {
     GameObject _obj = PhotonNetwork.Instantiate("Stone/Prefabs/" + stoneType.ToString(), position, rotation, 0);
     StoneNetwork _c = _obj.GetComponent<StoneNetwork>();
     _c.playerId = PhotonNetwork.player.ID;
     _c.stoneType = stoneType;
     return _c;
 }
Пример #7
0
 private SammokuBoard Add(int row, int col, StoneType player)
 {
     if (player == StoneType.None)
     {
         throw new ArgumentException("Noneは打てません");
     }
     board[row, col] = player;
     return(this);
 }
Пример #8
0
        public double Evaluate(Board board, StoneType stoneType)
        {
            if (board == null)
            {
                throw new ArgumentNullException(nameof(board));
            }

            return(board.GetCellsWithStone(stoneType).Sum(c => _weight[c.Position.RowIndex][c.Position.ColumnIndex]));
        }
Пример #9
0
 /// <summary>
 /// 石を置けるセルを取得
 /// </summary>
 /// <param name="stoneType"></param>
 /// <returns></returns>
 public IEnumerable <Cell> GetSelectableCells(StoneType stoneType)
 {
     foreach (var cell in GetEmptyCells())
     {
         if (CanSelectCell(cell.Position, stoneType))
         {
             yield return(cell);
         }
     }
 }
Пример #10
0
 /// <summary>
 /// 選択
 /// </summary>
 /// <param name="pos"></param>
 /// <param name="stoneType"></param>
 /// <returns>石を置けたとき:true</returns>
 public bool SetStone(CellPosition pos, StoneType stoneType)
 {
     if (CanSelectCell(pos, stoneType))
     {
         _cellsBackup = Cells.Clone();
         Cells.First(c => c.Position.Equals(pos)).Value = stoneType;
         return(true);
     }
     return(false);
 }
Пример #11
0
    void AddStone()
    {
        var g = Instantiate(stoneTemplate, inventory.stoneStorage.transform);

        g.name = "Stone";

        stoneType     = StoneType.None;
        stoneMaxMagic = 0f;
        stoneRecMagic = 0f;
    }
Пример #12
0
 public Color GetColor(StoneType type)
 {
     foreach (var s in sprites)
     {
         if (s.type == type)
         {
             return(s.color);
         }
     }
     return(Color.black.A(0));
 }
Пример #13
0
 public Sprite GetSprite(StoneType type)
 {
     foreach (var s in sprites)
     {
         if (s.type == type)
         {
             return(s.sprite);
         }
     }
     return(null);
 }
 void UpdateTypeSelecting()
 {
     curSelectingType = StoneType.None;
     foreach (var s in selectors)
     {
         var dist = ((Vector2)s.renderer.transform.position).To(Util.cursorWorldPosition).magnitude / curScale;
         if (dist <= typeSelectRadius)
         {
             curSelectingType = s.type;
             break;
         }
     }
 }
Пример #15
0
    public int Count(StoneType type)
    {
        int res = 0;

        for (int i = 0; i < maxCount; i++)
        {
            if (this[i] == type)
            {
                res++;
            }
        }
        return(res);
    }
        //ViewModelの更新(とViewへの通知)
        public void Update(Game game = null)
        {
            if (game == null)
            {
                if (service == null)
                {
                    throw new System.Exception();
                }

                game = service.GetGame();
            }

            //更新
            Board.Clear();
            for (int y = 0; y < game.Board.Height; y++)
            {
                var row = new ObservableCollection <CellViewModel>();
                for (int x = 0; x < game.Board.Width; x++)
                {
                    row.Add(new CellViewModel()
                    {
                        CellType = CellType.NotCell, X = x, Y = y
                    });
                }
                Board.Add(row);
            }

            foreach (var cell in game.Board.GetAllCells())
            {
                if (cell.Stone == null)
                {
                    Board[cell.Position.Y][cell.Position.X].CellType = CellType.Empty;
                }
                else
                {
                    Board[cell.Position.Y][cell.Position.X].CellType  = CellType.PutStone;
                    Board[cell.Position.Y][cell.Position.X].StoneType = cell.Stone;
                }
            }

            foreach (var cell in game.GetCanPutCellsOfCurrentTurn())
            {
                Board[cell.Position.Y][cell.Position.X].CellType = CellType.EmptyAndCanPut;
            }

            CurrentPlayer = game.CurrentTurn;

            //通知
            PutStoneCommand?.RaiseCanExecuteChanged();
            RaisePropertyChanged(null);
        }
Пример #17
0
    // Adding a stone object to a game object.
    public static Stone AddStone(GameObject obj, BoardPosition pos, bool isWhite, StoneType type = StoneType.Flat)
    {
        Stone stone = obj.AddComponent <Stone>();

        stone.SetPosition(pos);
        stone.isWhite   = isWhite;
        stone.StoneType = type;

        if (type == StoneType.Standing)
        {
            stone.transform.Rotate(new Vector3(90, 45, 0));
        }

        return(stone);
    }
Пример #18
0
        override public bool IsValidMove(BoardState board)
        {
            // First two moves need to be placements.
            bool correctPlayerIsActing = (board.GetActivePlayer() == Actor);
            bool normalTurn            = (board.HistoryMoveStack.Count >= 2);
            bool validStartingPosition = (board.IsInside(StartPosition));

            if (!correctPlayerIsActing || !normalTurn || !validStartingPosition)
            {
                return(false);
            }

            bool actorOwnsStack     = (board[StartPosition].Count > 0 && board[StartPosition].Peek().Owner == Actor);
            bool stoneLimitObeyed   = (NumStonesTaken <= board.BoardSize);
            bool enoughStones       = (NumStonesTaken <= board[StartPosition].Count);
            bool alwaysDroppedStone = (NumStonesDroppedPerField.Min() > 0);

            if (!actorOwnsStack || !stoneLimitObeyed || !enoughStones || !alwaysDroppedStone)
            {
                return(false);
            }

            // Moving a single capstone in the end can flatten a wall.
            bool canFlattenWall = (NumStonesDroppedPerField[NumStonesDroppedPerField.Count - 1] == 1 &&
                                   board[StartPosition].Peek().Type == StoneType.Capstone);

            for (int step = 0; step < NumStonesDroppedPerField.Count; ++step)
            {
                // Moving outside the field?
                Vector2Int pos = StartPosition + (step + 1) * MoveDirection.ToVector();
                if (!board.IsInside(pos))
                {
                    return(false);
                }

                // Can place on top?
                StoneType top          = board[pos].Count > 0 ? board[pos].Peek().Type : StoneType.FlatStone;
                bool      placeStone   = (top == StoneType.FlatStone);
                bool      flattenStone = (top == StoneType.StandingStone &&
                                          canFlattenWall &&
                                          step == NumStonesDroppedPerField.Count - 1);
                if (!placeStone && !flattenStone)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #19
0
        /// <summary>
        /// 盤の情報をもとに思考し、次の手を返す
        /// </summary>
        /// <param name="board"></param>
        /// <param name="player"></param>
        /// <returns></returns>
        public Reversi.Core.ReversiMove Think(ReversiBoard board, StoneType player)
        {
            this.board  = board;
            this.player = player;
            legalMoves  = board.SearchLegalMoves(player); //合法手
            if (legalMoves.Count == 0)
            {
                throw new InvalidOperationException("合法手がありません");
            }
            else
            {
                var best     = 0;
                var bestMove = default(ReversiMove);
                foreach (var item in board.SearchLegalMoves(player))
                {
                    var child = board.AddStone(item.Row, item.Col, player);
                    switch (player)
                    {
                    case StoneType.None:
                        break;

                    case StoneType.Sente:
                        if (best < child.NumOfBlack())
                        {
                            best     = child.NumOfBlack();
                            bestMove = item;
                        }
                        break;

                    case StoneType.Gote:
                        if (best < child.NumOfWhite())
                        {
                            best     = child.NumOfWhite();
                            bestMove = item;
                        }
                        break;

                    default:
                        break;
                    }
                }
                return(bestMove);
            }
        }
Пример #20
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="board"></param>
        /// <param name="selfStoneType"></param>
        /// <param name="evaluator"></param>
        public MinMaxFunctionSelector(Board board, StoneType selfStoneType, IEvaluator evaluator)
        {
            _board    = board;
            _selfType = selfStoneType;
            if (_selfType == StoneType.White)
            {
                _nonSelfType = StoneType.Black;
            }
            else if (_selfType == StoneType.Black)
            {
                _nonSelfType = StoneType.White;
            }
            else
            {
                _nonSelfType = StoneType.None;
            }

            _evaluationValues = new Dictionary <CellPosition, double>();
            _evaluator        = evaluator;
        }
Пример #21
0
        /// <summary>
        /// 合法手を探す
        /// </summary>
        /// <returns>合法手のリスト</returns>
        public List <ReversiMove> SearchLegalMoves(StoneType player)
        {
            var res = new List <ReversiMove>();

            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    try
                    {
                        AddStone(row, col, player);
                        res.Add(new ReversiMove(row, col));
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            }
            return(res);
        }
Пример #22
0
        /// <summary>
        /// 選択できるか
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="stoneType"></param>
        /// <returns></returns>
        public bool CanSelectCell(CellPosition pos, StoneType stoneType)
        {
            if (!GetEmptyCells().Any(c => c.Position.Equals(pos)))
            {
                return(false);
            }

            if (GetUpperRightLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetRightLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetLowerRightLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetLowerLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetLowerLeftLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetLeftLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetUpperLeftLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            if (GetUpperLineStones(pos, stoneType).Any())
            {
                return(true);
            }
            return(false);
        }
Пример #23
0
    void Start()
    {
        if (Client.Instance)
        {
            IsWhite = Client.Instance.isWhite;
        }
        else
        {
            IsWhite = true;
        }

        CurrentGameState = IsWhite ? GameState.TURN_START : GameState.OPPONENTS_TURN;

        allowedMoves = new bool[GameManager.Instance.BoardSize, GameManager.Instance.BoardSize];
        moveStart    = MouseController.GetInvalidPosition();
        FirstTurn    = true;

        currentStone = StoneType.Flat;
        SetupGameStates();
        PrepareActiveStones();
        CreateBoard();
    }
Пример #24
0
        public void FillStones(BitBoard board, StoneType color)
        {
            for (var i = 0; i < Constants.StonesCount; i++)
            {
                stones[i].Type = StoneType.Empty;
            }

            Action <ulong, StoneType> FillStonesByColor = (b, c) =>
            {
                for (var i = 0; i < Constants.StonesCount; i++)
                {
                    if ((b & (1UL << i)) != 0)
                    {
                        stones[i].Type = c;
                    }
                }
            };

            FillStonesByColor(board.PlayerPieces, color);

            FillStonesByColor(board.OpponentPieces, color.Opp());
        }
Пример #25
0
    public           StoneType this[int k]
    {
        get
        {
            switch (k)
            {
            case 0: return(a);

            case 1: return(b);

            case 2: return(c);

            case 3: return(d);

            case 4: return(e);

            default: break;
            }
            return(StoneType.None);
        }

        set
        {
            switch (k)
            {
            case 0: a = value; return;

            case 1: b = value; return;

            case 2: c = value; return;

            case 3: d = value; return;

            case 4: e = value; return;

            default: break;
            }
        }
    }
Пример #26
0
 /// <summary>
 /// 石を裏返す
 /// </summary>
 /// <param name="pos"></param>
 /// <param name="stoneType"></param>
 public Task TurnStoneAsync(CellPosition pos, StoneType stoneType)
 {
     return(Task.Run(() =>
     {
         foreach (var stone in GetUpperRightLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetRightLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetLowerRightLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetLowerLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetLowerLeftLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetLeftLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetUpperLeftLineStones(pos, stoneType))
         {
             stone.Turn();
         }
         foreach (var stone in GetUpperLineStones(pos, stoneType))
         {
             stone.Turn();
         }
     }));
 }
Пример #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="posList"></param>
        /// <param name="selfType"></param>
        /// <returns></returns>
        private List <Cell> GetTurnableStones(IEnumerable <CellPosition> posList, StoneType selfType)
        {
            var otherType      = selfType == StoneType.Black ? StoneType.White : StoneType.Black;
            var turnableStones = new List <Cell>();

            foreach (var p in posList)
            {
                if (Cells[p.RowIndex][p.ColumnIndex].Value == otherType)
                {
                    turnableStones.Add(Cells[p.RowIndex][p.ColumnIndex]);
                    continue;
                }
                if (Cells[p.RowIndex][p.ColumnIndex].Value == selfType)
                {
                    return(turnableStones);
                }
                if (Cells[p.RowIndex][p.ColumnIndex].Value == StoneType.None)
                {
                    return(new List <Cell>());
                }
            }
            return(new List <Cell>());
        }
Пример #28
0
 /// <summary>
 /// 石があるセルを取得する
 /// </summary>
 /// <param name="stoneType"></param>
 /// <returns></returns>
 public IEnumerable <Cell> GetCellsWithStone(StoneType stoneType)
 {
     return(Cells.Where(c => c.Value == stoneType));
 }
Пример #29
0
 public static StoneNetwork Create(StoneType stoneType)
 {
     return Create(stoneType, STONE_POSITIONS[(int)stoneType], Quaternion.identity);
 }
Пример #30
0
 /// <summary>
 /// 上の座標
 /// </summary>
 /// <param name="pos"></param>
 /// <param name="selfType"></param>
 private List <Cell> GetUpperLineStones(CellPosition pos, StoneType selfType)
 {
     return(GetTurnableStones(GetUpperLinePosition(pos), selfType));
 }
Пример #31
0
 public SetStoneAction(StoneType stoneType)
 {
     StoneType = stoneType;
 }
Пример #32
0
 public void Init(StoneType st)
 {
     this.stoneType = st;
 }
Пример #33
0
	public void SetStoneType(StoneType type, PlayerType player = PlayerType.None , int level = 0)
	{

	}
Пример #34
0
 // Flattens a standing stone.
 public void Flatten()
 {
     transform.rotation = new Quaternion();
     StoneType          = StoneType.Flat;
     SetPosition(this.Position);
 }
Пример #35
0
    /// <summary>
    /// While script is observed (in a PhotonView), this is called by PUN with a stream to write or read.
    /// </summary>
    /// <remarks>
    /// The property stream.isWriting is true for the owner of a PhotonView. This is the only client that
    /// should write into the stream. Others will receive the content written by the owner and can read it.
    /// 
    /// Note: Send only what you actually want to consume/use, too!
    /// Note: If the owner doesn't write something into the stream, PUN won't send anything.
    /// </remarks>
    /// <param name="stream">Read or write stream to pass state of this GameObject (or whatever else).</param>
    /// <param name="info">Some info about the sender of this stream, who is the owner of this PhotonView (and GameObject).</param>
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        Debug.Log ("OnPhotonSerializeView");
        if (stream.isWriting)
        {
            Vector3 pos = transform.localPosition;
            Quaternion rot = transform.localRotation;
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref playerId);
            int _st = (int)stoneType;
            stream.Serialize(ref _st);
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            int _st = (int)stoneType;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref playerId);
            stream.Serialize(ref _st);

            latestCorrectPos = pos;                 // save this to move towards it in FixedUpdate()
            onUpdatePos = transform.localPosition;  // we interpolate from here to latestCorrectPos
            fraction = 0;                           // reset the fraction we alreay moved. see Update()
            transform.localRotation = rot;          // this sample doesn't smooth rotation
            stoneType = (StoneType)_st;
        }
    }