public static CellPosition[] ParseList(string s)
 { 
     var charAry = s.ToCharArray();
     var result = new CellPosition[charAry.Length / 2];
     for (var i = 0; i < charAry.Length; i += 2)
     {
         result[i / 2] = Parse(charAry[i] + "" + charAry[i + 1]);
     }
     return result;
 }
Beispiel #2
0
        public override MazeSolution Solve(Maze maze, CellPosition startCellPosition, CellPosition escapeCellPosition)
        {
            this.maze            = maze;
            this.currentPosition = startCellPosition;

            path.Add(currentPosition);
            while (path.Count < movesLimit && currentPosition != escapeCellPosition)
            {
                Move();
            }

            return(new MazeSolution
            {
                FullPath = path,
                Solution = new List <CellPosition>()
            });
        }
Beispiel #3
0
        private void UpdateValueByCursorX(CellPosition cellPos, float x)
        {
            // calcutate value by cursor position
            float value = x / (Bounds.Width - 2f);

            if (value < 0)
            {
                value = 0;
            }
            if (value > 1)
            {
                value = 1;
            }

            Worksheet.SetCellData(cellPos, value);
            Worksheet.Workbook.Recalculate();
        }
Beispiel #4
0
        public FileStreamResult CreateExcelToClient()
        {
            int          page = 0, rows = 0;
            int          CellPositionID = Convert.ToInt32(Request.QueryString["ID"]);
            string       CellCode       = Request.QueryString["CellCode"];
            string       CellName       = Request.QueryString["CellName"];
            CellPosition cp             = new CellPosition();

            cp.ID       = CellPositionID;
            cp.CellCode = CellCode;

            ExportParam ep = new ExportParam();

            ep.DT1        = CellPositionService.GetCellPosition(page, rows, cp);
            ep.HeadTitle1 = "货位位置信息";
            return(PrintService.Print(ep));
        }
        private void SearchText(eSearchKind kind, string text)
        {
            if (grid == null || grid.Rows.Count == 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            var targetCellIndex = 0;

            if (kind == eSearchKind.CustomerCode)
            {
                targetCellIndex = grid.Columns["celDispCustomerCode"].Index;
            }
            if (kind == eSearchKind.CustomerName)
            {
                targetCellIndex = grid.Columns["celDispCustomerName"].Index;
            }
            if (kind == eSearchKind.PayerName)
            {
                targetCellIndex = grid.Columns["celPayerName"].Index;
            }

            var startRowIndex = (grid.CurrentCellPosition.CellIndex != targetCellIndex) ? grid.CurrentCellPosition.RowIndex : grid.CurrentCellPosition.RowIndex + 1;
            var p             = new CellPosition(-1, -1);

            if (startRowIndex < grid.Rows.Count)
            {
                p = grid.Search(text, new CellPosition(startRowIndex, targetCellIndex), new CellPosition(grid.Rows.Count - 1, targetCellIndex), false, SearchFlags.None, SearchOrder.NOrder);
            }
            if (p.RowIndex < 0)
            {
                p = grid.Search(text, new CellPosition(0, targetCellIndex), new CellPosition(startRowIndex, targetCellIndex), false, SearchFlags.None, SearchOrder.NOrder);
            }
            if (p.RowIndex < 0)
            {
                ShowWarningDialog(MsgWngNotExistSearchData);
            }
            else
            {
                ClearStatusMessage();
                grid.CurrentCellPosition = p;
            }
        }
Beispiel #6
0
            /// <summary>
            /// 確定ボタン押下
            /// </summary>
            /// <param name="parameter"></param>
            public void Execute(object parameter)
            {
                CellCommandParameter cellCommandParameter = (CellCommandParameter)parameter;
                var    parent = ViewBaseCommon.FindVisualParent <TKS90010>(this._gcSpreadGrid);
                string msg    = string.Empty;

                if (cellCommandParameter.Area == SpreadArea.Cells)
                {
                    int rowNo     = cellCommandParameter.CellPosition.Row;
                    var row       = this._gcSpreadGrid.Rows[rowNo];
                    var fixKbn    = row.Cells[(int)GridColumnsMapping.確定区分].Value;
                    var fixDay    = row.Cells[(int)GridColumnsMapping.確定日].Value;
                    var closeDay  = row.Cells[(int)GridColumnsMapping.締日].Value;
                    var toriKbn   = row.Cells[(int)GridColumnsMapping.取引区分ID].Value;
                    var toriKbnNm = row.Cells[(int)GridColumnsMapping.取引区分].Value;
                    var jisCode   = row.Cells[(int)GridColumnsMapping.自社コード].Value;

                    // エラー情報をクリア
                    row.ValidationErrors.Clear();

                    if (fixDay == null || fixDay.ToString() == DEFAULT_YYMMDD)
                    {
                        msg = "確定日を設定してください。";
                        CellPosition cp = new CellPosition(rowNo, GridColumnsMapping.確定日.GetHashCode());
                        this._gcSpreadGrid[cp].ValidationErrors.Add(new SpreadValidationError(msg, null));
                        MessageBox.Show(msg);
                        return;
                    }

                    if (MessageBox.Show(
                            string.Format("{0}日締の{1}を {2} で確定登録します。\n確定日以前の伝票は編集できなくなります。\nよろしいですか?"
                                          , closeDay.ToString()
                                          , toriKbnNm.ToString()
                                          , fixDay.ToString()),
                            "登録確認",
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Question,
                            MessageBoxResult.Yes) == MessageBoxResult.No)
                    {
                        return;
                    }

                    // 登録処理を呼び出し
                    parent.UpdateTableData(jisCode.ToString(), fixKbn.ToString(), closeDay.ToString(), fixDay.ToString(), toriKbn.ToString());
                }
            }
        private void MatCurrentColumnEvaluate()
        {
            CellPosition editPos = grdMaterials.EditedCell;

            if (!editPos.IsValid)
            {
                return;
            }

            if (cursorAtColumn == colItem.Index)
            {
                MatItemEvaluate(editPos.Row, grdMaterials.EditedCellValue.ToString());
            }
            else if (cursorAtColumn == colQuantity.Index)
            {
                MatQtyEvaluate(editPos.Row, grdMaterials.EditedCellValue.ToString());
            }
        }
        private void ProdCurrentColumnEvaluate()
        {
            CellPosition editPos = grdProducts.EditedCell;

            if (!editPos.IsValid)
            {
                return;
            }

            if (cursorAtColumn == colSecondItem.Index)
            {
                ProdItemEvaluate(editPos.Row, grdProducts.EditedCellValue.ToString());
            }
            else if (cursorAtColumn == colSecondQuantity.Index)
            {
                ProdQtyEvaluate(editPos.Row, grdProducts.EditedCellValue.ToString());
            }
        }
        /** ボックス内を検索。
         */
        private bool FindCellBox(int a_x, int a_y, int a_size, string a_text, out CellPosition a_result_pos)
        {
            for (int yy = 0; yy < a_size; yy++)
            {
                for (int xx = 0; xx < a_size; xx++)
                {
                    int t_x = a_x + xx;
                    int t_y = a_y + yy;
                    if (this.CellStringCheck(t_x, t_y, a_text, out a_result_pos) == true)
                    {
                        return(true);
                    }
                }
            }

            a_result_pos = new CellPosition(0, 0);
            return(false);
        }
Beispiel #10
0
        void RemoveStyle_RestoreToOriginal()
        {
            SetUp(20, 20);

            var pos = new CellPosition("B2");

            worksheet.SetRangeStyles(new RangePosition(pos, pos), new WorksheetRangeStyle
            {
                Flag      = PlainStyleFlag.BackColor,
                BackColor = Color.Silver,
            });

            worksheet.RemoveRangeStyles(new RangePosition(pos, pos), PlainStyleFlag.BackColor);

            var style = worksheet.GetCellStyles(pos);

            AssertEquals(style.BackColor, Color.Empty, "BackColor not removed");
        }
Beispiel #11
0
    public GridDweller[] CellContents(CellPosition position)
    {
        GridDweller[] contents = new GridDweller[] { };

        if (IsValid(position))
        {
            if (position.side == GridClass.PlayerGrid)
            {
                return(playerSideContents[position.x, position.z].ToArray());
            }
            else if (position.side == GridClass.EnemyGrid)
            {
                return(enemySideContents[position.x, position.z].ToArray());
            }
        }

        return(contents);
    }
Beispiel #12
0
        private static List <CellState> GetNeighbouringCellStates(ReadOnlyGrid concernedCells)
        {
            var neighbouringCells = new List <CellState>();

            for (var rowIndex = 0; rowIndex < 3; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < 3; columnIndex++)
                {
                    if (!IsCenterCell(rowIndex, columnIndex))
                    {
                        var cellPosition = new CellPosition(rowIndex, columnIndex);
                        neighbouringCells.Add(concernedCells.GetCellState(cellPosition));
                    }
                }
            }

            return(neighbouringCells);
        }
Beispiel #13
0
    protected override void Load()
    {
        Debug.Log("Loading World");
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                CellPosition pos = new CellPosition(i, j);

                int  index = Random.Range(0, seedCells.Length);
                Cell c     = seedCells [index];
                c = Instantiate(c);
                c.transform.parent = this.transform;
                c.Pos = pos;
                AddCell(pos, seedCells [index]);
            }
        }
    }
 private void SearchRemainingCells()
 {
     for (int x = 0; x < settings.mazeWidth; x++)
     {
         for (int y = 0; y < settings.mazeLength; y++)
         {
             if (!cells[x, y].visited && IsNextToMaze(x, y))
             {
                 currentPosition = new CellPosition {
                     x = x, y = y
                 };
                 // Debug.Log("Starting at: [ " + currentPosition.x.ToString() + ", " + currentPosition.y.ToString() + "]");
                 ConnectCellToMaze();
                 BreakWalls(settings.mazeWidth, settings.mazeLength);
             }
         }
     }
 }
        public void RememberTarget_AfterMiss()
        {
            var knowledge = new GameFieldKnowledge(gameController.Rules.FieldSize);

            A.CallTo(() => player1.OpponentFieldKnowledge).Returns(knowledge);

            var target     = new CellPosition(5, 6);
            var shotResult = ShotResult.Miss(target);

            A.CallTo(() => player2.SelfField.Shoot(target)).Returns(shotResult);

            gameController.Shoot(target).Should().Be(shotResult);

            foreach (var position in knowledge.EnumeratePositions())
            {
                knowledge[position].Should().Be(position.Equals(target) ? (bool?)false : null);
            }
        }
Beispiel #16
0
    private void GenerateSpawnPos(int x = -1, int y = -1)
    {
        if (x >= 0 && y >= 0)
        {
            tabCells[x, y].obj = Cell.CASE_OBJECT.Spawn;
            spawnPos           = new CellPosition(x, y);
            return;
        }

        int roomIndex = Random.Range(0, rooms.Count);

        spawnRoom = roomIndex;

        CellPosition spawnRoomPos = rooms[roomIndex];

        tabCells[spawnRoomPos.x, spawnRoomPos.y].obj = Cell.CASE_OBJECT.Spawn;
        spawnPos = new CellPosition(spawnRoomPos.x, spawnRoomPos.y);
    }
Beispiel #17
0
        public CellPosition GetCellAiChoseBasedOnBoard(Cell[,] board)
        {
            bool pickRandom = Random.Range(0, 3) == 0;
            RandomAiChooseLogic simpleRandomChooseLogic = new RandomAiChooseLogic(board);
            CellPosition        totallyRandomCell       = simpleRandomChooseLogic.ChooseRandomCell();

            /*
             * if(pickRandom) //Small chance for the computer to take it easy and just choose a random one
             * {
             *  return totallyRandomCell;
             * }
             */

            //Try to do a "hard" AI Algorithm. What we do is check all rows/columns if they have a row/column with more than 1 of the Player symbols.
            //if yes we try and make the COM spawn one on that row. If that fails for all of them use the totallyRandom one we chose above. A more
            //correct AI would check if it could also win the game on the next move but I didn't want it to always end in ties. For this one
            // I am only making it to "stop the player" from winning.
            List <CellPosition> cellsFree = simpleRandomChooseLogic.GetAllFreeCells();

            int[] rowPlayerChosenInfo = GetRowPlayerChosenData(board);  //Find number of player symbols for each row
            for (int i = 0; i < rowPlayerChosenInfo.Length; i++)
            {
                foreach (var cell in cellsFree)
                {
                    if (rowPlayerChosenInfo[i] > 1 && cell.x == i)
                    {
                        return(cell);
                    }
                }
            }
            int[] columnPlayerChosenInfo = GetColumnPlayerChosenData(board); //Find number of player symbols for each column
            for (int i = 0; i < columnPlayerChosenInfo.Length; i++)
            {
                foreach (var cell in cellsFree)
                {
                    if (columnPlayerChosenInfo[i] > 1 && cell.y == i)
                    {
                        return(cell);
                    }
                }
            }
            //If nothing of interest found above use the totally random cell
            return(totallyRandomCell);
        }
        protected override void btnClear_Clicked(object sender, EventArgs e)
        {
            if (!AskForOperationClear())
            {
                return;
            }

            if (editMode)
            {
                CellPosition gridMatEditPos = grid.EditedCell;
                if (gridMatEditPos.IsValid && gridMatEditPos.Column == colQuantity.Index)
                {
                    grid.CancelCellEdit();
                }

                CellPosition gridProdEditPos = secondGrid.EditedCell;
                if (gridProdEditPos.IsValid && gridProdEditPos.Column == colSecondQuantity.Index)
                {
                    secondGrid.CancelCellEdit();
                }

                operation.ClearDetails();

                if (gridMatEditPos.IsValid)
                {
                    EditGridField(gridMatEditPos.Row, gridMatEditPos.Column);
                }

                if (gridProdEditPos.IsValid)
                {
                    EditSecondGridField(gridProdEditPos.Row, gridProdEditPos.Column);
                }
            }
            else
            {
                operation.ClearDetails();
                operation.AddNewDetail();
                operation.AddNewAdditionalDetail();

                EditGridField(0, colItem.Index);
                OperationTotalHide();
            }
        }
    public bool NewCell(CellPosition position, Vector2 cellCenter)
    {
        Vector2 newCellCenter;

        switch (position)
        {
        case CellPosition.TOP:
            newCellCenter = new Vector2(cellCenter.x, cellCenter.y + scaleY);
            break;

        case CellPosition.BOTTOM:
            newCellCenter = new Vector2(cellCenter.x, cellCenter.y - scaleY);
            break;

        case CellPosition.LEFT:
            newCellCenter = new Vector2(cellCenter.x - scaleX, cellCenter.y);
            break;

        case CellPosition.RIGHT:
            newCellCenter = new Vector2(cellCenter.x + scaleX, cellCenter.y);
            break;

        default:
            newCellCenter = cellCenter;
            break;
        }

        if (cellExists(newCellCenter))
        {
            return(false);
        }

        GameObject newCell = Instantiate(cell, newCellCenter, Quaternion.identity);

        activeCellCoordinates.Add(newCellCenter);
        newCell.transform.parent = gameObject.transform;
        Cell cellInfo = newCell.GetComponent <Cell>();

        cellInfo.grapplePointPrefab = grapplePointPrefab;
        cellInfo.grid = this;
        cellInfo.Initialise();
        return(true);
    }
Beispiel #20
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var table  = new Table();
            var player = Player.Dark;

            string record = req.Query["record"];

            if (!string.IsNullOrEmpty(record))
            {
                var pts = CellPosition.ParseList(record.ToLower().Trim());
                player = table.Reset(pts);
            }
            else
            {
                table.Reset();
            }

            var random        = new Random();
            var placableCells = table.GetPlaceableCells(player).ToArray();

            if (placableCells.Length == 0)
            {
                // pass or gameover.
                return(new OkObjectResult(record));
            }

            var index = random.Next(placableCells.Length);
            var next  = placableCells[index];

            if (table.TryPlace(next, player))
            {
                return(new OkObjectResult(record + next.ToString()));
            }
            else
            {
                // TODO: Error
                return(new EmptyResult());
            }
        }
Beispiel #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="player"></param>
        /// <returns></returns>
        public bool IsPlaceable(CellPosition pos, Player player)
        {
            var state = GetCell(pos)?.State ?? CellState.None;

            if (state != CellState.None)
            {
                return(false);
            }

            return
                (IsPlaceableByDirection(pos, -1, -1, player) || // left, top
                 IsPlaceableByDirection(pos, -1, 0, player) ||  // top
                 IsPlaceableByDirection(pos, -1, 1, player) ||  // right, top
                 IsPlaceableByDirection(pos, 0, -1, player) ||  // left
                 IsPlaceableByDirection(pos, 0, 1, player) ||   // right
                 IsPlaceableByDirection(pos, 1, -1, player) ||  // left, bottom
                 IsPlaceableByDirection(pos, 1, 0, player) ||   // bottom
                 IsPlaceableByDirection(pos, 1, 1, player));    // right;
        }
Beispiel #22
0
        private bool IsDeadEnd(CellPosition cell)
        {
            if (cell == startCellPosition && !visitedCells.Contains(cell))
            {
                return(false);
            }

            var nClosedSides = 0;

            for (int i = 0; i < 4; ++i)
            {
                if (maze[cell].GetSideByNumber(i) == SideState.Closed)
                {
                    nClosedSides++;
                }
            }

            return(nClosedSides >= 3);
        }
Beispiel #23
0
        public static CellPosition GetCellPosition(string posString)
        {
            CellPosition cp = new CellPosition();

            int row = 0;
            int col = 0;
            int i   = 0;

            for (; i < posString.Length; ++i)
            {
                char c = posString[i];
                if ('a' <= c && c <= 'z')
                {
                    col = col * 26 + c - 'a' + 1;
                }
                else if ('A' <= c && c <= 'Z')
                {
                    col = col * 26 + c - 'A' + 1;
                }
                else
                {
                    break;
                }
            }

            for (; i < posString.Length; ++i)
            {
                char c = posString[i];
                if ('0' <= c && c <= '9')
                {
                    row = row * 10 + c - '0';
                }
                else
                {
                    throw new System.Exception("Parse link cell position errro for c=" + c);
                }
            }
            //索引号从0开始
            cp.row = row - 1;
            cp.col = col - 1;

            return(cp);
        }
Beispiel #24
0
 private bool HasObjNear(CellPosition pos)
 {
     foreach (Cell.CASE_OBJECT objType in Enum.GetValues(typeof(Cell.CASE_OBJECT)))
     {
         if (objType == Cell.CASE_OBJECT.None)
         {
             continue;
         }
         if (objType == Cell.CASE_OBJECT.Count)
         {
             continue;
         }
         if (GetNearObjDirection(pos, objType) != DIRECTION.None)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #25
0
 public bool IsTypeInCell(CellPosition position, DwellerType type)
 {
     if (!IsValid(position))
     {
         return(false);
     }
     if (position.side == GridClass.PlayerGrid)
     {
         return(playerSideContents[position.x, position.z].Exists(
                    delegate(GridDweller dweller) { return dweller.type == type; }
                    ));
     }
     else
     {
         return(enemySideContents[position.x, position.z].Exists(
                    delegate(GridDweller dweller) { return dweller.type == type; }
                    ));
     }
 }
Beispiel #26
0
        public List <CellPosition> GetAllFreeCells()
        {
            List <CellPosition> allFreeCells = new List <CellPosition>();

            for (int i = 0; i < m_Board.GetLength(0); i++)
            {
                for (int j = 0; j < m_Board.GetLength(1); j++)
                {
                    if (m_Board[i, j].CellData == CellStatus.UNOCCUPIED)
                    {
                        CellPosition currentIteratingCellPos = new CellPosition {
                            x = i, y = j
                        };
                        allFreeCells.Add(currentIteratingCellPos);
                    }
                }
            }
            return(allFreeCells);
        }
        private CellPosition GetRandomUnvisitedCellPos()
        {
            var unvisitedCellPositions = new List <CellPosition>();

            for (int i = 0; i < maze.Height; ++i)
            {
                for (int j = 0; j < maze.Width; ++j)
                {
                    var cellPosition = new CellPosition(i, j);
                    if (!IsVisited(cellPosition))
                    {
                        unvisitedCellPositions.Add(cellPosition);
                    }
                }
            }

            var randomIndex = rand.Next(0, unvisitedCellPositions.Count);

            return(unvisitedCellPositions[randomIndex]);
        }
        public override MazeSolution Solve(Maze maze, CellPosition startCellPosition, CellPosition escapeCellPosition)
        {
            this.maze       = maze;
            currentPosition = startCellPosition;
            deltaCol        = 0;
            deltaRow        = 1;
            directionNumber = 2;

            while (currentPosition != escapeCellPosition)
            {
                Move();
            }
            visited.Add(new CellPosition(maze.Height - 1, maze.Width - 1));

            return(new MazeSolution
            {
                FullPath = visited,
                Solution = FinalPath()
            });
        }
Beispiel #29
0
        public static bool TryGetPosFromValue(Worksheet sheet, object arg, out CellPosition pos)
        {
            if (arg is object[])
            {
                object[] args = (object[])arg;

                return(TryGetPosFromArgs(sheet, args, out pos));
            }
            else if (arg is ObjectValue)
            {
                var obj = (ObjectValue)arg;

                pos = new CellPosition(ScriptRunningMachine.GetIntValue(obj["row"]),
                                       ScriptRunningMachine.GetIntValue(obj["col"]));
                return(true);
            }

            pos = CellPosition.Empty;
            return(false);
        }
Beispiel #30
0
    public bool MoveTorwards(CellPosition target, EntityMap map, GroundMap groundMap)
    {
        var dx       = target.x - actor.entity.position.x;
        var dy       = target.y - actor.entity.position.y;
        var distance = (int)Mathf.Sqrt(dx * dx + dy * dy);

        dx = dx / distance;
        dy = dy / distance;

        var newX = actor.entity.position.x + dx;
        var newY = actor.entity.position.y + dy;

        if (!groundMap.IsBlocked(newX, newY) && map.GetBlockingEntityAtPosition(newX, newY) == null)
        {
            Move(dx, dy);
            return(true);
        }

        return(false);
    }
Beispiel #31
0
 private void AddSerialsFromRange(RangePosition serialNamesRange, RangePosition serialsRange,
                                  RowOrColumn serialPerRowOrColumn = RowOrColumn.Row)
 {
     if (serialPerRowOrColumn == RowOrColumn.Row)
     {
         for (int r = serialsRange.Row; r <= serialsRange.EndRow; r++)
         {
             var label = new CellPosition(r, serialNamesRange.Col);
             this.AddSerial(worksheet, label, new RangePosition(r, serialsRange.Col, 1, serialsRange.Cols));
         }
     }
     else
     {
         for (int c = serialsRange.Col; c <= serialsRange.EndCol; c++)
         {
             var label = new CellPosition(serialNamesRange.Row, c);
             this.AddSerial(worksheet, label, new RangePosition(serialsRange.Row, c, serialsRange.Rows, 1));
         }
     }
 }
Beispiel #32
0
 public CellPositionEvaluation(CellPosition pt, int ev)
 {
     Position = pt;
     Evaluation = ev;
 }
    private IEnumerable<CellPosition> GetReversibleCellPositionsByDirection(int row, int column, int dr, int dc, Player player)
    {
        var own = player.ToCellState();
        var other = player.GetOtherPlayer().ToCellState();

        var ncp = new CellPosition(row + dr, column + dc);
        if (GetCellState(ncp.Row, ncp.Column) != other)
        {
            return new CellPosition[0];
        }

        var list = new List<CellPosition>() { ncp };
        for(var icp = new CellPosition(ncp.Row + dr, ncp.Column + dc);
            icp.Row >= 0 && icp.Column >= 0 &&
            icp.Row < Rows && icp.Column < Columns;
            icp = new CellPosition(icp.Row + dr, icp.Column + dc)
        )
        {
            var cell = GetCellState(icp.Row, icp.Column);
            if (cell == other) { list.Add(icp); }
            else if (cell == own) { return list; }
            else { break; }
        }
        return new CellPosition[0];
    }
    private IEnumerator PlaceAnime(CellPosition pt, Player player)
    {
        var positions = GetReversibleCellPositions(pt, player);
        if (positions.Length == 0) { yield break; }
        
        // 新規に自分の石を置く
        _othelloCells[pt.Row, pt.Column].CellState = player.ToCellState();

        // 挟まれた石をひっくり返す
        var list = new List<OthelloCellView>();
        foreach(var rcpt in positions)
        {
            var cell = _othelloCells[rcpt.Row, rcpt.Column];
            var e = cell.UpdateCell(player.ToCellState());
            list.Add(cell);

            StartCoroutine(e);
            yield return new WaitForSeconds(0.1F);
        }

        while (true)
        {
            var isContinue = false;
            foreach (var cell in list)
            {
                if (cell.CellState != player.ToCellState())
                {
                    isContinue = true;
                    break;
                }
            }

            if (!isContinue) { break; }
            yield return null;
        }
    }
Beispiel #35
0
 private void GoNext(CellPosition pt)
 {
     _record += pt.ToString();
     Place(pt.Row, pt.Column, _currentPlayer);
     var other = _currentPlayer.GetOtherPlayer();
     if (HasPlaceableCell(other)) { _currentPlayer = other; }
     else { _isGameOver = !HasPlaceableCell(_currentPlayer); }
 }
    private int Eval(CellPosition pt, Player player, bool isRec)
    {
        var result = 0;
        var mr = Rows - 1;
        var mc = Columns - 1;

        if (pt.IsCorner(mr, mc)) { result += 10; }
        else if (pt.IsCornerAdjacent(mr, mc)) { result -= 3; }
        if (pt.IsBorder(mr, mc)) { result += 5; }

        var rpt = GetReversibleCellPositions(pt, player);
        result += rpt.Length;

        var record = "";
        foreach (var r in _record) record += r.ToString();

        if (isRec)
        {
            GoNext(pt);
            foreach (var ppt in GetPlaceableCellPositions(_currentPlayer))
            {
                var ev = Eval(ppt, _currentPlayer, false);
                if (ev > 10) result -= (ev - 8);
            }
        }

        Reset(CellPosition.ParseList(record));
        
        return result;
    }
 private CellPosition[] GetPlaceableCellPositions(Player player)
 {
     var placeableCellPositions = new List<CellPosition>();
     for (var r = 0; r < Rows; r++)
     {
         for (var c = 0; c < Columns; c++)
         {
             if (IsPlaceable(r, c, player))
             {
                 var pt = new CellPosition(r, c);
                 placeableCellPositions.Add(pt);
             }
         }
     }
     return placeableCellPositions.ToArray();
 }
 private IEnumerator UpdatePlayer()
 {
     while (true)
     {
         if (Input.GetKeyDown(KeyCode.U)) { Undo(); }
         if (Input.GetKeyDown(KeyCode.Escape)) { Reset(); }
         if (Input.GetKeyDown(KeyCode.DownArrow)) { SelectedRow++; }
         if (Input.GetKeyDown(KeyCode.UpArrow)) { SelectedRow--; }
         if (Input.GetKeyDown(KeyCode.RightArrow)) { SelectedColumn++; }
         if (Input.GetKeyDown(KeyCode.LeftArrow)) { SelectedColumn--; }
         if (Input.GetKeyDown(KeyCode.Return))
         {
             if (IsPlaceable(SelectedRow, SelectedColumn, _currentPlayer))
             {
                 var pt = new CellPosition(SelectedRow, SelectedColumn);
                 GoNext(pt);
                 //yield return StartCoroutine(GoNextAnime(pt));
                 UpdatePlaceableCells(_currentPlayer);
                 break;
             }
         }
         yield return null;
     }
 }
Beispiel #39
0
 public static List<Point> GetWallOutline(CellPosition cpWallLocation)
 {
     if (cpWallLocation == CellPosition.Left)
         return new List<Point>(new Point[] { new Point(0, 8), new Point(4, 0), new Point(4, 8), new Point(0, 16), new Point(0, 8) });
     else if (cpWallLocation == CellPosition.Front)
         return new List<Point>(new Point[] { new Point(4, 0), new Point(4, 8), new Point(12, 8), new Point(12, 0), new Point(4, 0) });
     else if (cpWallLocation == CellPosition.Right)
         return new List<Point>(new Point[] { new Point(12, 0), new Point(16, 8), new Point(16, 16), new Point(12, 8), new Point(12, 0) });
     return new List<Point>(new Point[] { new Point(0, 0) });
 }
 private int Eval(CellPosition pt, Player player)
 {
     return UnityEngine.Random.Range(0, 100);
 }
    private CellPosition SelectCellPosition(CellPosition[] cellPositions)
    {
        if (_currentPlayer == Player.Black)
        {
            var pteList = new List<CellPositionEvaluation>();
            foreach (var pt in cellPositions)
            {
                var ev = Eval(pt, _currentPlayer, true);
                pteList.Add(new CellPositionEvaluation(pt, ev));
            }

            var max = int.MinValue;
            var selectedPt = default(CellPosition);
            foreach (var pte in pteList)
            {
                if (pte.Evaluation > max)
                {
                    max = pte.Evaluation;
                    selectedPt = pte.Position;
                }
            }
            return selectedPt;
        }
        return SelectCellPositionRandom(cellPositions);
    }
     GetReversibleCellPositions(CellPosition pt, Player player)
 {
     var list = new List<CellPosition>();
     list.AddRange(GetReversibleCellPositionsByDirection(pt, -1, -1, player));//左上
     list.AddRange(GetReversibleCellPositionsByDirection(pt, -1, 0, player)); //上
     list.AddRange(GetReversibleCellPositionsByDirection(pt, -1, 1, player)); //右上
     list.AddRange(GetReversibleCellPositionsByDirection(pt, 0, -1, player)); //左
     list.AddRange(GetReversibleCellPositionsByDirection(pt, 0, 1, player)); //右
     list.AddRange(GetReversibleCellPositionsByDirection(pt, 1, -1, player)); //左下
     list.AddRange(GetReversibleCellPositionsByDirection(pt, 1, 0, player)); //下
     list.AddRange(GetReversibleCellPositionsByDirection(pt, 1, 1, player)); //右
     return list.ToArray();
 }
Beispiel #43
0
        /// <summary>
        /// Gets the cell position for a given day.
        /// </summary>
        /// <returns>
        /// The cell position for day, as a CellPosition object.
        /// </returns>
        /// <param name='day'>
        /// Day to get the coordinates for.
        /// </param>
        public CellPosition GetCellPositionForDay(int day)
        {
            var toret = new CellPosition();

            // Check for a valid day
            if ( day < 1
              || day > this.LastDay.Day )
            {
                throw new ArgumentOutOfRangeException(
                    "GetCellPositionForDay(), day: " + Convert.ToString( day ) );
            }

            // Do it -- yep, this is a sequential search
            // Tired of calculating (and always nearly working)
            for(int i = 0; i < this.grdDayGrid.Rows.Count; ++i) {
                var cells = this.grdDayGrid.Rows[ i ].Cells;

                for(int j = 0; j < cells.Count; ++j) {
                    int calDay = 0;
                    string value = (string) cells[ j ].Value;

                    if ( value != null ) {
                        if ( int.TryParse( value.Trim(), out calDay ) ) {
                            if ( day == calDay ) {
                                toret.Row = i;
                                toret.Col = j;
                                break;
                            }
                        }
                    }
                }
            }

            return toret;
        }
 private IEnumerator GoNextAnime(CellPosition pt)
 {
     yield return StartCoroutine(PlaceAnime(pt, _currentPlayer));
     GoNext(pt);
 }
Beispiel #45
0
    private IEnumerable<CellPosition> GetReversableCellPositionsByDirection(int row, int column, int nr, int nc, CellState player, CellState other)
    {
        var npt = new CellPosition(row + nr, column + nc);
        if (GetCellState(npt.Row, npt.Column) != other)
        {
            return new CellPosition[0];
        }

        var list = new List<CellPosition>();
        list.Add(npt);
        for (
            var ipt = new CellPosition(npt.Row + nr, npt.Column + nc);
            ipt.Row >= 0 && ipt.Column >= 0 &&
            ipt.Row < Rows && ipt.Column < Columns;
            ipt.Row += nr, ipt.Column += nc)
        {
            var s = GetCellState(ipt.Row, ipt.Column);
            if (s == player) { return list; }
            else if (s == other) { list.Add(ipt); }
            else { break; }
        }
        return new CellPosition[0];
    }
Beispiel #46
0
 public void MoveCell(GameTime time, CellPosition diff)
 {
     MoveToCell(time, c_position + diff);
 }
     SelectCellPositionCount(CellPosition[] cellPositions, Player player)
 {
     var max = 0;
     var maxCellPosition = cellPositions[0];
     foreach(var pt in cellPositions)
     {
         var cellPts = GetReversibleCellPositions(pt, player);
         if (cellPts.Length > max)
         {
             max = cellPts.Length;
             maxCellPosition = pt;
         }
     }
     return maxCellPosition;
 }
 private CellPosition SelectCellPositionRandom(CellPosition[] cellPositions)
 {
     var index = Random.Range(0, cellPositions.Length);
     return cellPositions[index];
 }
Beispiel #49
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Left)
            {
                if (Control.ModifierKeys != Keys.Control)
                {
                    this.Rows.UnselectAllCells();
                }
                CellPosition position = GetCell(e.Location);
                position.row.SelectCell(position.col.Name);
                this.first_selected = position;
                onNeedResize();
            }

            this.Focus();
        }
 private void Reset(CellPosition[] record)
 {
     Reset();
     foreach(var pt in record) { GoNext(pt); }
 }
    private void Place(CellPosition pt, Player player)
    {
        var positions = GetReversibleCellPositions(pt, player);
        if (positions.Length == 0) { return; }

        // 新規に自分の石を置く
        _othelloCells[pt.Row, pt.Column].CellState = player.ToCellState();
        foreach (var rcpt in positions)
        {
            var cell = _othelloCells[rcpt.Row, rcpt.Column];
            cell.CellState = player.ToCellState();
        }
    }
        GetReversibleCellPositionsByDirection(
            CellPosition pt, int dr, int dc, Player player)
    {
        var other = player.ToOtherPlayer().ToCellState();
        var npt = new CellPosition(pt.Row + dr, pt.Column + dc);
        if (GetCellState(npt.Row, npt.Column) != other)
        {
            return new CellPosition[0];
        }

        var list = new List<CellPosition>();
        list.Add(npt);
        var pc = player.ToCellState();
        for (
            var ipt = new CellPosition(npt.Row + dr, npt.Column + dc);
            ipt.Row >= 0 && ipt.Column >= 0 &&
            ipt.Row < Rows && ipt.Column < Columns;
            ipt = new CellPosition(ipt.Row + dr, ipt.Column + dc))
        {
            var s = GetCellState(ipt.Row, ipt.Column);
            if (s == pc) { return list.ToArray(); }
            else if (s == other) { list.Add(ipt); }
            else { break; }
        }
        return new CellPosition[0];
    }
Beispiel #53
0
        /// <summary>
        /// Gets the day for a given cell position.
        /// </summary>
        /// <returns>
        /// The day for cell position.
        /// </returns>
        /// <param name='pos'>
        /// Position.
        /// </param>
        public int GetDayForCellPosition(CellPosition pos)
        {
            // Check for sanity
            if ( pos.Row < 0
              || pos.Col < 0 )
            {
                throw new ArgumentOutOfRangeException( "invalid cell: " + pos.ToString() );
            }

            // Do it
            string strDay = (string) this.grdDayGrid.Rows[ pos.Row ].Cells[ pos.Col ].Value;
            int toret = 1;

            if ( strDay != null ) {
                strDay = strDay.Trim();
                if (!( Int32.TryParse( strDay, out toret ) )) {
                    toret = 1;
                }
            } else {
                throw new ArgumentOutOfRangeException( "invalid cell: " + pos.ToString() );
            }

            return toret;
        }
    private IEnumerator UpdateUser()
    {
        while (true)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            { UpdateSelectedCell(SelectedRow - 1, SelectedColumn); }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            { UpdateSelectedCell(SelectedRow + 1, SelectedColumn); }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            { UpdateSelectedCell(SelectedRow, SelectedColumn - 1); }
            if (Input.GetKeyDown(KeyCode.RightArrow))
            { UpdateSelectedCell(SelectedRow, SelectedColumn + 1); }

            if (Input.GetKeyDown(KeyCode.Escape)) { Reset(); break; }
            if (Input.GetKeyDown(KeyCode.Return)
                && IsPlaceable(SelectedRow, SelectedColumn, _currentPlayer))
            {
                var pt = new CellPosition(SelectedRow, SelectedColumn);
                GoNext(pt);
                UpdatePlaceableCells();
                UpdateStoneCount();
                break;
            }
            yield return null;
        }
    }
    private void GoNext(CellPosition pt)
    {
        _record.Add(pt);
        Place(pt, _currentPlayer);

        var other = _currentPlayer.ToOtherPlayer();
        if (HasPlaceableCell(other)) { _currentPlayer = other; }
        else if (!HasPlaceableCell(_currentPlayer))
        {
            _isGameOver = true;
        }
        UpdateStoneCount();
    }
Beispiel #56
0
 /// <summary>
 /// Highlights the cell.
 /// </summary>
 /// <param name='pos'>
 /// Position.
 /// </param>
 protected void HighlightCell(CellPosition pos)
 {
     this.HighlightCell( pos.Row, pos.Col );
 }
Beispiel #57
0
        public void MoveToCell(GameTime time, CellPosition newPos)
        {
            var now = time.TotalGameTime.TotalSeconds;

            if (newPos != c_position)
            {
                if (World.IsPassable(newPos))
                {
                    _transitionFromPosition = Position;
                    _transitionToPosition = newPos.ToPixelPosition();
                    _transitionStartTime = now;

                    c_position = newPos;

                    _lastMoveTime = now;
                    OnMove(time);
                }
            }
        }
Beispiel #58
0
 /// <summary>
 /// Marks the cell as holiday.
 /// </summary>
 /// <param name='pos'>
 /// The position of the cell, as a CellPosition object.
 /// </param>
 protected void MarkCellAsHoliday(CellPosition pos)
 {
     this.MarkCellAsHoliday( pos.Row, pos.Col );
 }
Beispiel #59
0
        public static List<Point> GetArchOutline(CellPosition cpArchLocation)
        {
            if (cpArchLocation == CellPosition.Left)
                return new List<Point>(new Point[] { new Point ( 0, 8 ), new Point ( 4, 0 ), new Point ( 4, 8 ), new Point ( 3, 10 ), new Point ( 3, 4 ), new Point ( 1, 8 ), new Point ( 1, 14 ),
                    new Point ( 0, 16 ), new Point ( 0, 8 ) });

            else if (cpArchLocation == CellPosition.Front)
                return new List<Point>(new Point[] { new Point ( 4,8), new Point ( 4,0), new Point (12, 0), new Point (12, 8), new Point (10,8), new Point (10,2), new Point ( 6, 2),
                    new Point (6, 8), new Point ( 4,8) });

            else if (cpArchLocation == CellPosition.Right)
                return new List<Point>(new Point[] { new Point ( 12, 0 ), new Point ( 16, 8 ), new Point ( 16, 16 ), new Point ( 15, 14 ), new Point ( 15, 8 ), new Point ( 13, 4 ), new Point ( 13, 10 ),
                    new Point ( 12, 8 ), new Point ( 12, 0 ) });

            return new List<Point>(new Point[] { new Point(0, 0) });
        }
 private OthelloCellView CreateCell(CellPosition pt)
 {
     var cell = Instantiate(OthelloCell);
     cell.name = OthelloCell.name + "(" + pt.Row + "," + pt.Column + ")";
     cell.transform.Translate(1.05F * pt.Column, 0, -1.05F * pt.Row);
     cell.transform.parent = gameObject.transform;
     return cell.GetComponent<OthelloCellView>();
 }