/// <summary>
 /// Sets a grid cell only if inside grid bounds, does nothing if is out of bounds
 /// </summary>
 /// <param name="x">X coordinate</param>
 /// <param name="y">Y coordinate</param>
 /// <param name="content">content to set</param>
 public void SetCell(int x, int y, CellContent content)
 {
     if (x >= 0 && x < this.size && y >= 0 && y < this.size)
     {
         this.Table[x, y].Content = content;
     }
 }
Beispiel #2
0
        private void AddNode(int root, CellContent content, float globalCost)
        {
            Node node = new Node(all.Count, root, globalCost, 0, content);

            all.Add(node);
            HeapAdd(node);
        }
Beispiel #3
0
        public void Set(CellPosition position, Entity cell, CellContent content)
        {
            string key = GetKey(position.x, position.y);

            _entities[key] = cell;
            _contents[key] = content;
        }
Beispiel #4
0
        public EntryCellView(Context context, Cell cell)
            : base(context, cell)
        {
            _editText = new CustomEditText(context)
            {
                Focusable             = true,
                ImeOptions            = ImeAction.Done,
                OnFocusChangeListener = this,
                Ellipsize             = TextUtils.TruncateAt.End,
                ClearFocusAction      = DoneEdit,
                Background            = _Context.GetDrawable(Android.Resource.Color.Transparent)
            };
            _editText.SetPadding(0, 0, 0, 0);
            _editText.SetOnEditorActionListener(this);
            _editText.SetSingleLine(true);
            _editText.InputType |= InputTypes.TextFlagNoSuggestions; // Disabled spell check

            Click += EntryCellView_Click;

            using (var lParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                               ViewGroup.LayoutParams.WrapContent))
            {
                CellContent.AddView(_editText, lParams);
            }

            if (_debugWithColors)
            {
                _editText.Background = _Context.GetDrawable(Android.Resource.Color.HoloRedLight);
            }
        }
Beispiel #5
0
        public override void PrintCell(CellContent cell)
        {
            switch (cell)
            {
            case CellContent.empty:
                Console.Write(".");
                break;

            case CellContent.ship:
                Console.Write(".");
                break;

            case CellContent.hitShip:
                Console.Write("X");
                break;

            case CellContent.destroyedShip:
                Console.Write("Z");
                break;

            case CellContent.missedShot:
                Console.Write("/");
                break;

            default:
                Console.Write("Error, wrong enum in cell!");
                break;
            }
        }
Beispiel #6
0
        /****************************************/

        private void AddCheckerInLane(CellContent cellType, int lane)
        {
            int i, j;

            if (lane <= numOfRows)                             //lower board
            {
                i = numOfRows - numOfCheckersInLane[lane] - 1; //skip the occupied cells
                j = rowSize - lane;
                if (i >= oneSideSize)                          //board is full (don't show the new stone)
                {
                    BoardMatrix[i, j] = cellType;
                }
            }
            else //upper board
            {
                i = numOfCheckersInLane[lane];
                j = lane - rowSize - 1;
                if (i < oneSideSize)
                {
                    BoardMatrix[i, j] = cellType;
                }
            }

            RowOccupation[lane - 1] = cellType;
            numOfCheckersInLane[lane]++;
        }
Beispiel #7
0
        private static Evaluation EvaluateCell(Board board, int x, int y)
        {
            CellContent whoseLine = board.GetCell(x, y);
            CellContent next      = board.LastMove.Who == CellContent.Bot ? CellContent.Player : CellContent.Bot;

            LineParams[] cellParams = board.CellParams(x, y);
            foreach (LineParams lineParams in cellParams)
            {
                int  l  = lineParams.Length;
                int  oe = lineParams.OpenEnds;
                bool nextIsNotWhoseLineWins = (l == 5) || (l == 4 && oe == 2);
                bool nextIsWhoseLineWins    = nextIsNotWhoseLineWins || (l == 4 && oe == 1) || (l == 3 && oe == 2);
                if (next == CellContent.Player && whoseLine == CellContent.Bot && nextIsNotWhoseLineWins)
                {
                    return(Evaluation.Good);
                }
                if (next == CellContent.Player && whoseLine == CellContent.Player && nextIsWhoseLineWins)
                {
                    return(Evaluation.Bad);
                }
                if (next == CellContent.Bot && whoseLine == CellContent.Bot && nextIsWhoseLineWins)
                {
                    return(Evaluation.Good);
                }
                if (next == CellContent.Bot && whoseLine == CellContent.Player && nextIsNotWhoseLineWins)
                {
                    return(Evaluation.Bad);
                }
            }
            return(Evaluation.Neutral);
        }
Beispiel #8
0
 public Node(int index, int root, float g, float h, CellContent content)
 {
     this.index   = index;
     this.root    = root;
     this.g       = g;
     this.h       = h;
     this.content = content;
 }
Beispiel #9
0
 public CellPath(CellPath existedPath, CellContent newConnection)
 {
     this.start       = existedPath.start;
     this.connections = new List <CellContent>(existedPath.connections);
     this.connections.Add(newConnection);
     this.path = new List <Cell>(existedPath.path);
     this.path.Add(newConnection.connection);
 }
Beispiel #10
0
        public static DataTable Fill(DataTable table, int rows, CellContent cellContent)
        {
            for (int rowIndex = 0; rowIndex < rows; rowIndex++)
            {
                FillRow(table, rowIndex, cellContent);
            }

            return(table);
        }
Beispiel #11
0
        public static DataTable Create(string name, int rows, CellContent cellContent, params TypeCode[] columns)
        {
            var table = new DataTable(name);

            CreateHeader(table, columns);
            Fill(table, rows, cellContent);

            return(table);
        }
Beispiel #12
0
 public void Refresh()
 {
     for (int i = 0; i < m.getHH(); i++)
     {
         for (int j = 0; j < m.getWW(); j++)
         {
             CellContent c = m.getMapCell(i, j).getContent();
         }
     }
 }
Beispiel #13
0
        public void Test_Sodoku_Grid()
        {
            Sodoku sodoku = new Sodoku();

            // top left
            sodoku[2, 2] = new CellContent(9);
            int rank = sodoku[2, 2].Rank;

            Assert.AreEqual(9, sodoku[2, 2].Rank);
            SodokuItem row = sodoku.GetRowAt(2);

            Assert.AreEqual(9, row[2].Rank);
            SodokuItem col = sodoku.GetColumnAt(2);

            Assert.AreEqual(9, col[2].Rank);
            Sodoku3x3 sgrid = sodoku.GetSodoku3x3AtGridPosition(2, 2);

            Assert.AreEqual(9, sgrid[2, 2].Rank);

            // bottom right
            sodoku[7, 8] = new CellContent(1);
            rank         = sodoku[7, 8].Rank;
            Assert.AreEqual(rank, sodoku[7, 8].Rank);
            row = sodoku.GetRowAt(8);
            Assert.AreEqual(rank, row[7].Rank);
            col = sodoku.GetColumnAt(7);
            Assert.AreEqual(rank, col[8].Rank);
            sgrid = sodoku.GetSodoku3x3AtGridPosition(7, 8);
            Assert.AreEqual(rank, sgrid[1, 2].Rank);

            // middle
            sodoku[4, 5] = new CellContent(5);
            rank         = sodoku[4, 5].Rank;
            Assert.AreEqual(rank, sodoku[4, 5].Rank);
            row = sodoku.GetRowAt(5);
            Assert.AreEqual(rank, row[4].Rank);
            col = sodoku.GetColumnAt(4);
            Assert.AreEqual(rank, col[5].Rank);
            sgrid = sodoku.GetSodoku3x3AtGridPosition(4, 5);
            Assert.AreEqual(rank, sgrid[1, 2].Rank);

            // middle bottom
            sodoku[5, 7] = new CellContent(2);
            rank         = sodoku[5, 7].Rank;
            Assert.AreEqual(rank, sodoku[5, 7].Rank);
            row = sodoku.GetRowAt(7);
            Assert.AreEqual(rank, row[5].Rank);
            col = sodoku.GetColumnAt(5);
            Assert.AreEqual(rank, col[7].Rank);
            sgrid = sodoku.GetSodoku3x3AtGridPosition(5, 7);
            Assert.AreEqual(rank, sgrid[2, 1].Rank);

            Assert.IsTrue(sodoku.Validate());
            //sodoku.
        }
Beispiel #14
0
        private static GameObject Generate(CellContent content, int row, int column, string name = null)
        {
            var y        = content == CellContent.Start || content == CellContent.End ? 2.5f : 0f;
            var position = new Vector3(column * NodeDimension, y, -row * NodeDimension);
            var go       = (GameObject)Object.Instantiate(Utils.RelatedResource(content),
                                                          position: position,
                                                          rotation: Quaternion.identity);

            go.name = name ?? go.name.Split('(')[0];
            return(go);
        }
Beispiel #15
0
 public bool AddFood()
 {
     if (WhatsHere != CellContent.Empty)
     {
         return(false);
     }
     else
     {
         WhatsHere = CellContent.Food;
         return(true);
     }
 }
 /// <summary>
 /// Initializes a ship setting his position default to an invalid -1,-1 cell
 /// but setting it's size and initializing the ship cells
 /// </summary>
 /// <param name="size">The ship's size</param>
 /// <param name="content">The ship's cell content</param>
 protected Ship(int size, CellContent content)
 {
     this.PosX    = -1;
     this.PosY    = -1;
     this.Size    = size;
     this.Content = content;
     this.Cells   = new bool[this.Size];
     for (var i = 0; i < size; i++)
     {
         this.Cells[i] = false;
     }
 }
Beispiel #17
0
        /****************************************/

        public Board()
        {
            BoardMatrix         = new CellContent[numOfRows, rowSize];
            RowOccupation       = new CellContent[numOfRows * 2];
            EatenCheckers       = new List <CellContent>();
            numOfCheckersInLane = new Dictionary <int, int>();

            for (int i = 1; i < 25; i++)
            {
                numOfCheckersInLane[i] = 0;
            }
        }
Beispiel #18
0
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            CellContent cc = dgSearched.SelectedCells[0].Item as CellContent;

            if (cc.StackerID == 1)
            {
                stacker1.take(cc.CellID);
            }
            else if (cc.StackerID == 2)
            {
                // stacker2.take(cc.CellID);
            }
        }
Beispiel #19
0
        public void SwapCells(Position p1, Position p2)
        {
            CellContent content1 = m.getMapCell(p1.getX, p1.getY).getContent();
            CellContent content2 = m.getMapCell(p2.getX, p2.getY).getContent();

            gameObject.transform.GetChild(p1.getY + p1.getX * m.getWW()).GetComponent <uCell>()
            .fillContent(content2);
            gameObject.transform.GetChild(p2.getY + p2.getX * m.getWW()).GetComponent <uCell>()
            .fillContent(content1);

//            m.setMapCell(p1.getX, p1.getY, content1);
//            m.setMapCell(p2.getX, p2.getY, content2);
        }
Beispiel #20
0
        /// <summary>
        /// Set given content in random place in game area
        /// </summary>
        /// <param name="content">Content that should be showed in game area, like apple or spikes</param>
        public static void Plant(CellContent content)
        {
            var position = new Position();

            do
            {
                Random randomNumberGenerator = new Random();
                position.X = randomNumberGenerator.Next(0, (int)(GameState.sideCellCount - 1));
                position.Y = randomNumberGenerator.Next(0, (int)(GameState.sideCellCount - 1));
            } while (CellContainsSomethingOrSnakeIsThere(ref position));

            GameState.grid.SetCellContent(ref position, content);
        }
Beispiel #21
0
        public static void PassJudgement(CellContent cellContent, int neighbouringAmebaCount)
        {
            switch (cellContent)
            {
            case Ameba ameba:
                PassJudgementOnAmeba(ameba, neighbouringAmebaCount);
                break;

            case EmptyCell emptyCell:
                DecideFutureOfEmptyCell(emptyCell, neighbouringAmebaCount);
                break;
            }
        }
Beispiel #22
0
        internal bool Play(int column, CellContent cellContent)
        {
            for (int row = 0; row < NUMBER_OF_ROWS; row++)
            {
                if (Cells[column, row] == CellContent.Empty)
                {
                    Cells[column, row] = cellContent;
                    return(true);
                }
            }

            return(false);
        }
Beispiel #23
0
    private CellContent[,] CloneCells()
    {
        var clone = new CellContent[NUMBER_OF_COLUMNS, NUMBER_OF_ROWS];

        for (var c = 0; c < NUMBER_OF_COLUMNS; c++)
        {
            for (var r = 0; r < NUMBER_OF_ROWS; r++)
            {
                clone[c, r] = this.Cells[c, r];
            }
        }
        return(clone);
    }
Beispiel #24
0
        public void Test_Sodoku_Available()
        {
            Sodoku sodoku = new Sodoku();

            List <int> available = sodoku.AvailableRanks(4, 4);

            Assert.AreEqual(9, available.Count);

            sodoku[4, 1] = new CellContent(1);

            var col = sodoku.GetColumnAt(4);

            Assert.AreEqual(8, col.AvailableRanks().Count);

            available = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(8, available.Count);

            sodoku[1, 4] = new CellContent(1);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(8, available.Count);

            sodoku[2, 4] = new CellContent(2);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(7, available.Count);

            sodoku[4, 8] = new CellContent(3);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(6, available.Count);

            sodoku[3, 3] = new CellContent(4);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(5, available.Count);

            sodoku[5, 5] = new CellContent(5);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(4, available.Count);

            sodoku[7, 4] = new CellContent(6);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(3, available.Count);

            sodoku[4, 7] = new CellContent(7);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(2, available.Count);

            sodoku[3, 5] = new CellContent(8);
            available    = sodoku.AvailableRanks(4, 4);
            Assert.AreEqual(1, available.Count);

            Assert.AreEqual(9, available[0]);
        }
Beispiel #25
0
        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            // move to first load cell
            CellContent cc = dgSearched.SelectedCells[0].Item as CellContent;

            if (cc.StackerID == 1)
            {
                stacker1.move_free_priem(cc.CellID);
            }
            else if (cc.StackerID == 2)
            {
                //   stacker2.move_free_priem(cc.CellID);
            }
        }
Beispiel #26
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                CellBase.PropertyChanged   -= CellPropertyChanged;
                CellParent.PropertyChanged -= ParentPropertyChanged;
                CellButton1.Click          -= CellButton1_Click;
                CellButton2.Click          -= CellButton2_Click;
                CellButton3.Click          -= CellButton3_Click;

                if (CellBase.Section != null)
                {
                    CellBase.Section.PropertyChanged -= SectionPropertyChanged;
                    CellBase.Section = null;
                }

                CellTitle?.Dispose();
                CellTitle = null;
                CellTitleContent?.Dispose();
                CellTitleContent = null;
                CellAccessory?.Dispose();
                CellAccessory = null;
                CellButton1?.Dispose();
                CellButton1 = null;
                CellButton2?.Dispose();
                CellButton2 = null;
                CellButton3?.Dispose();
                CellButton3 = null;
                CellButtonContent?.Dispose();
                CellButtonContent = null;
                CellContent?.Dispose();
                CellContent = null;
                Cell        = null;

                _iconTokenSource?.Dispose();
                _iconTokenSource = null;
                _Context         = null;

                _backgroundColor?.Dispose();
                _backgroundColor = null;
                _selectedColor?.Dispose();
                _selectedColor = null;
                _ripple?.Dispose();
                _ripple = null;

                Background?.Dispose();
                Background = null;
            }
            base.Dispose(disposing);
        }
Beispiel #27
0
        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (_cellContentFromDataContext != null)
            {
                _cellContentFromDataContext.PropertyChanged -= _cellContent_PropertyChanged;
            }

            _cellContentFromDataContext = DataContext as CellContent;
            if (_cellContentFromDataContext != null)
            {
                _cellContentFromDataContext.PropertyChanged += _cellContent_PropertyChanged;
            }
            ControlTypeChanged();
        }
Beispiel #28
0
    public CellContent[] GameView(PlayerColor playerColor)
    {
        unsafe
        {
            byte *        raw = CAPI.TendrilGameView(m_cgame, playerColor);
            CellContent[] dynamic_allocated_cells = new CellContent[m_boardSize];
            for (uint i = 0; i < m_boardSize; ++i)
            {
                // This depends strictly on CellContent values matching the C API definitons.
                dynamic_allocated_cells[i] = (CellContent)raw[i];
            }

            return(dynamic_allocated_cells);
        }
    }
Beispiel #29
0
        protected override void CreateControlHierarchy()
        {
            base.CreateControlHierarchy();

            CellContent.Add(
                CBContainerTable   = RenderUtils.CreateTable().Add(
                    CBContainerRow = RenderUtils.CreateTableRow()
                    )
                );

            CreatePerformSearchButton();
            CreateSeparatorCell();
            CreateCancelSearchButton();
            CreatePlaceholderCell();
        }
        public void TestInvalidCreateFieldLayoutByCellContent(CellContent param, InvalidValue invalid)
        {
            var handler     = new DefaultManager();
            var fieldUuid   = FieldsCreator.Data[$"{ResourceId.Client}-{FieldType.SingleLineText.ToString()}-0"].Guid;
            var request     = GenerateFieldLayoutRequest(ResourceId.Client, fieldUuid, Title.MinJa, Row.Min, Column.Min, CellContent.Field);
            var createParam = request[Parameters.Create.GetEnumStringValue()] as Dictionary <string, object>;
            var cells       = (createParam[Parameters.Cells.GetEnumStringValue()] as List <Dictionary <string, object> >).First();
            var cellContent = cells[Cell.Content.GetEnumStringValue()] as Dictionary <string, object>;

            InvalidValueMapper[invalid](cellContent, param.GetEnumStringValue());
            createParam[Parameters.Cells.GetEnumStringValue()] = cellContent;
            request[Parameters.Create.GetEnumStringValue()]    = createParam;
            var response = handler.Send <object>(FieldManager.FieldLayoutApiRelativeUrl, JsonConvert.SerializeObject(request), HttpMethod.POST);

            PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
        }
Beispiel #31
0
        /// <summary>
        /// Gets the content.
        /// </summary>
        /// <param name="mincross">Минимальная разница яркости ячейки с кретсиком</param>
        /// <param name="maxcross">Максимальная разница яркости ячейки с кретсиком</param>
        public void GetContent(double mincross, double maxcross)
        {
            _content = false;
            _neurocontent = CellContent.Free;

            List<double> _lrange = new List<double>();
            BitmapData data = _parentimage.LockBits(_rect, ImageLockMode.ReadWrite, _parentimage.PixelFormat);
            VerticalIntensityStatistics vis = new VerticalIntensityStatistics(data);
            histogram = vis.Gray;

            HorizontalIntensityStatistics his = new HorizontalIntensityStatistics(data);
            Histogram hhistogram = his.Gray;
            List<double> _hrange = new List<double>();

            _parentimage.UnlockBits(data);

            for (int i = 8; i <= 15; i++)
            {
                _lrange.Add((histogram.Values[i]+hhistogram.Values[i])/2);
               // _hrange.Add(hhistogram.Values[i]);
            }
              // _britnessdispertion = (1 - RecogCore.Statistics.Mean(_lrange) / histogram.Values.Max()) + (1 - RecogCore.Statistics.Mean(_hrange) / hhistogram.Values.Max());
            _britnessdispertion = 1 - RecogCore.Statistics.Mean(_lrange) / histogram.Values.Max();
            if (_britnessdispertion <= mincross) { _neurocontent = CellContent.Free; _content = false; }
            if (_britnessdispertion > mincross & _britnessdispertion <= maxcross) { _neurocontent = CellContent.Cross; _content = true; }
            if (_britnessdispertion > maxcross) { _neurocontent = CellContent.Miss; _content = false; }
        }
Beispiel #32
0
        /// <summary>
        /// Read the text file for recreating the saved world map
        /// </summary>
        /// <param name="filePath">A path to the file's location</param>
        /// <returns></returns>
        private CellContent[,] ReadFile(string filePath)
        {
            if (File.Exists(filePath))
            {
                string[] lines = File.ReadAllLines(filePath);
                string[] cellContents = lines[1].Split('\t');

                int countCellsForX = cellContents.Length - 1;
                int countCellsForY = lines.Length / 3;

                CellContent[,] cells = new CellContent[countCellsForX, countCellsForY];
                for (int y = 0; y < countCellsForY; y++)
                {
                    cellContents = lines[y * 3 + 1].Split('\t');
                    for (int x = 0; x < countCellsForX; x++)
                    {
                        switch (cellContents[x])
                        {
                            case "Goal":
                                cells[x, y] = CellContent.Goal;
                                break;
                            case "Wall":
                                cells[x, y] = CellContent.Wall;
                                break;
                            case "Blank":
                                cells[x, y] = CellContent.Blank;
                                break;
                            default:
                                 throw new InvalidMapException("Corrupt data: \"" + cellContents[x] + "\", actually expecting: Goal, Wall or Blank");
                        }
                    }
                }
                return cells;
            }
            return cells;
        }
Beispiel #33
0
 /// <summary>
 /// Write the world map in a text file
 /// </summary>
 /// <param name="cells">List of cells' location</param>
 private void WriteFile(CellContent[,] cells)
 {
     using (StreamWriter text = new StreamWriter("map.txt"))
     {
         for (int y = 0; y < Height; y++)
         {
             for (int x = 0; x < Width; x++)
             {
                 text.Write("[" + x + "," + y + "]\t");
             }
             text.WriteLine("");
             for (int x = 0; x < Width; x++)
             {
                 text.Write(CellContentAtCell(new Point(x, y)) + "\t");
             }
             text.WriteLine("\r\n");
         }
     }
 }