示例#1
0
 static Predicate<List<int>> ByGridForWhite(GridEntry entry, int i)
 {
     return delegate (List<int> x)
     {
         int iIndex = x.FindIndex(ByInt(i));
         bool bCanMoveForwardForWhite = iIndex + 1 < x.Count && iIndex >= 0 && x[iIndex] < x[iIndex + 1];
         bool b = iIndex != -1 && ((entry == GridEntry.WHITEPAWN && bCanMoveForwardForWhite) || entry == GridEntry.WHITEKING);
         return b;
     };
 }
示例#2
0
 public CheckGame(GridEntry[] testBoard)
 {
     GridEntry[] values = testBoard;
     init = new Board(values, true);
     Current = init;
 }
示例#3
0
 static Predicate<List<int>> ByGridForBlack(GridEntry entry, int i)
 {
     return delegate (List<int> x)
     {
         int iIndex = x.FindIndex(ByInt(i));
         bool bCanMoveForwardForBlack = iIndex - 1 >= 0 && x[iIndex] > x[iIndex - 1];
         bool b = iIndex != -1 && ((entry == GridEntry.BLACKPAWN && bCanMoveForwardForBlack) || entry == GridEntry.BLACKKING);
         return b;
     };
 }
示例#4
0
        private GridEntry[] TransformBoardToAIGridArray(int[,] boardArray)
        {
            GridEntry[] transformed = new GridEntry[BOARDSIZE * BOARDSIZE];

            for(int i = 0; i < BOARDSIZE; i++)
            {
                transformed[(BOARDSIZE * i)] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 0].ToString());
                transformed[(BOARDSIZE * i) + 1] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 1].ToString());
                transformed[(BOARDSIZE * i) + 2] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 2].ToString());
                transformed[(BOARDSIZE * i) + 3] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 3].ToString());
                transformed[(BOARDSIZE * i) + 4] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 4].ToString());
                transformed[(BOARDSIZE * i) + 5] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 5].ToString());
                transformed[(BOARDSIZE * i) + 6] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 6].ToString());
                transformed[(BOARDSIZE * i) + 7] = (GridEntry)Enum.Parse(typeof(GridEntry), boardArray[i, 7].ToString());
            }

            return transformed;
        }
示例#5
0
        private int GetOverallScore(GridEntry[] bArray)
        {
            int CountB = 0;
            int CountW = 0;
            int CountBK = 0;
            int CountWK = 0;
            //var bMoveLeftForBlack = false;
            //var bMoveLeftForWhite = false;

            

            //for (int i = 0; i < BoardArray.Count(); i++)
            //{
            //    var piece = BoardArray[i];
            //    if (piece == GridEntry.BLACKPAWN || piece == GridEntry.BLACKKING)
            //    {
            //        bMoveLeftForBlack = moveLeftForBlack(piece, i);
            //        if (bMoveLeftForBlack)
            //            break;
            //    }
            //}

            //for (int i = 0; i < BoardArray.Count(); i++)
            //{
            //    var piece = BoardArray[i];
            //    if (piece == GridEntry.WHITEKING || piece == GridEntry.WHITEPAWN)
            //    {
            //        bMoveLeftForWhite = moveLeftForWhite(piece, i);
            //        if (bMoveLeftForWhite)
            //            break;
            //    }
            //}

            //if ((m_TurnForPlayerBlack && !bMoveLeftForBlack) || (!m_TurnForPlayerBlack && !bMoveLeftForWhite))
            //    GameOver = true;

            for(int i = 0; i < bArray.Count(); i++)
            {
                var piece = bArray[i];
                if (piece == GridEntry.NULL || piece == GridEntry.EMPTY)
                    continue;

                if (piece == GridEntry.BLACKPAWN)
                {
                    CountB++;
                }

                if (piece == GridEntry.WHITEPAWN)
                {
                    CountW++;
                }

                if (piece == GridEntry.BLACKKING)
                {
                    CountB += 1;
                    CountBK += 3;
                }

                if (piece == GridEntry.WHITEKING)
                {
                    CountW += 1;
                    CountWK += 3;
                }
            }

            if (m_TurnForPlayerBlack)
            {
                return (CountBK * 3) + ((CountBK - CountWK) * 5) + (CountB - CountW);
            }

            return -((CountWK * 3) + ((CountWK - CountWK) * 5) + (CountW - CountB));
        }
示例#6
0
 internal PropertyDescriptorGridEntryTestEntity(PropertyGrid ownerGrid, GridEntry peParent, bool hide)
     : base(ownerGrid, peParent, hide)
 {
     _accessibleObject = new PropertyDescriptorGridEntryAccessibleObject(this);
 }
示例#7
0
 GridEntry getGridEntry()
 {
     ComboBoxItem typeItem = (ComboBoxItem)typeCB.SelectedItem;
     ComboBoxItem dTypeItem = (ComboBoxItem)dTypeCB.SelectedItem;
     GridEntry ret = new GridEntry();
     ret.type = typeItem.Content.ToString();
     ret.dataType = dTypeItem.Content.ToString();
     if (minValTB.IsEnabled == false)
     {
         ret.minValue = "N/A";
     }
     else
     {
         ret.minValue = minValTB.Text;
     }
     if (maxValTB.IsEnabled == false)
     {
         ret.maxValue = "N/A";
     }
     else
     {
         ret.maxValue = maxValTB.Text;
     }
     if (sizeXTB.IsEnabled == false)
     {
         ret.sizeX = "N/A";
     }
     else
     {
         ret.sizeX = sizeXTB.Text;
     }
     if (sizeYTB.IsEnabled == false)
     {
         ret.sizeY = "N/A";
     }
     else
     {
         ret.sizeY = sizeYTB.Text;
     }
     if (CharsTB.IsEnabled == false)
     {
         ret.chars = "N/A";
     }
     else
     {
         ret.chars = CharsTB.Text;
     }
     if (LengthTB.IsEnabled == false)
     {
         ret.length = "N/A";
     }
     else
     {
         ret.length = LengthTB.Text;
     }
     return ret;
 }
        public static Result GetMaxValue(int knapsackSize, Item[] items)
        {
            // Create calculation grid sized for the number of items and units of the knapsack size.
            var grid = new GridEntry[items.Length, knapsackSize];

            // Take each item in turn.
            for (var i = 0; i < items.Length; i++)
            {
                var currentItem = items[i];

                // Then loop through each of the units of knapsack size (i.e. if we have a size of 4, we'll check
                // intermediate sizes of 1, 2 and 3.
                for (var j = 0; j < knapsackSize; j++)
                {
                    // Item fits if it's weight is less than or equal to the intermediate knapsack size.
                    var doesItemFit = currentItem.Weight <= j + 1;

                    if (doesItemFit)
                    {
                        int previousMaxValue = 0, valueOfRemainingSpace = 0;
                        if (i > 0)
                        {
                            previousMaxValue = grid[i - 1, j].Value;
                            if (j - currentItem.Weight >= 0)
                            {
                                valueOfRemainingSpace = grid[i - 1, j - currentItem.Weight].Value;
                            }
                        }

                        // Item fits, so we can add it.
                        if (currentItem.Value + valueOfRemainingSpace > previousMaxValue)
                        {
                            // If the current value of the item plus the value of the remaining space is greater than the value added in the row
                            // above, then we'll populate the cell with the current item.
                            if (i == 0 || valueOfRemainingSpace == 0)
                            {
                                // If we're on the first row, or if there's nothing we can add in the remaining space, then
                                // we just put the current item in the cell by itself.
                                grid[i, j] = new GridEntry {
                                    Items = new[] { currentItem.Name }, Value = currentItem.Value
                                };
                            }
                            else
                            {
                                // Otherwise we add the current item plus the item(s) from the grid cell we've found that
                                // represents what else we can fit in.
                                var gridEntryToFillFrom = grid[i - 1, j - items[i].Weight];
                                var itemsForCell        = new List <string> {
                                    currentItem.Name
                                };
                                itemsForCell.AddRange(gridEntryToFillFrom.Items);
                                var valueForCell = currentItem.Value + gridEntryToFillFrom.Value;
                                grid[i, j] = new GridEntry {
                                    Items = itemsForCell.ToArray(), Value = valueForCell
                                };
                            }
                        }
                        else
                        {
                            // If the item being added is less than the value we've got already from the previous row,
                            // we just copy that over.
                            grid[i, j] = grid[i, j - 1];
                        }
                    }
                    else
                    {
                        // If the item doesn't fit, we either have an empty entry (for the first row), or we
                        // take whatever we filled for the intermediate knapsack size in the row above.
                        grid[i, j] = i == 0 ? new GridEntry() : grid[i - 1, j];
                    }
                }
            }

            // The result comes from the final entry in the grid.
            var finalEntry = grid[items.Length - 1, knapsackSize - 1];

            return(new Result
            {
                Items = string.Join(",", finalEntry.Items.OrderBy(x => x)),
                Value = finalEntry.Value,
            });
        }
 // Constructors
 public GridEntryAccessibleObject(GridEntry owner)
 {
 }
示例#10
0
 public GridEntry(CollisionSkin skin)
 {
     Skin     = skin;
     Previous = Next = null;
 }
 public DropDownEditablePropertyDescriptorGridEntry(PropertyGrid ownerGrid, GridEntry parent, PropertyDescriptor propertyDescriptor, bool hide)
     : base(ownerGrid, parent, propertyDescriptor, hide)
 {
 }
	// Constructors
	public GridEntryAccessibleObject(GridEntry owner) {}
示例#13
0
 private void KingPiece(GamePiece movingPiece, Image KingImage, GridEntry PromotionState)
 {
     Controls.Remove(movingPiece as Control);
     movingPiece.Image = KingImage;
     movingPiece.PieceState = PromotionState;
     movingPiece.IsPromoted = true;
     Controls.Add(movingPiece);
     Controls.SetChildIndex(movingPiece, 1001);
     movingPiece.BringToFront();
     AdjustBoard(movingPiece.BoardLocation, movingPiece.PieceState);
 }
示例#14
0
        private int[,] TransformGridToBoard(GridEntry[] grid)
        {
            int[,] bArray = new int[BOARDSIZE, BOARDSIZE];
            for(int i = 0; i < grid.Length; i++)
            {
                int iRow = i/8;
                int iColumn = i % 8;
                bArray[iRow, iColumn] = (int)grid[i];
            }

            return bArray;
        }
示例#15
0
        public List<Board> MoveForWhite(GridEntry piece, int i)
        {
            List<Board> PossibleBoards = new List<Board>();
            if (!m_TurnForPlayerBlack && (BoardArray[i] == GridEntry.WHITEKING || BoardArray[i] == GridEntry.WHITEPAWN))
            {
                List<List<int>> linesToEvaluate = new List<List<int>>();
                linesToEvaluate = gameLines.FindAll(ByGridForWhite(BoardArray[i], i));
                List<List<int>> linesEvaluated = new List<List<int>>();
                List<List<int>> extraLines = new List<List<int>>();

                if (BoardArray[i] == GridEntry.WHITEKING)
                {
                    foreach (var bline in linesToEvaluate)
                    {
                        List<int> nLine = new List<int>();
                        nLine.AddRange(bline);
                        extraLines.Add(nLine);
                    }
                }

                linesToEvaluate.AddRange(extraLines);

                foreach (var line in linesToEvaluate)
                {
                    bool bKingReverseLine = linesEvaluated.Contains(line);
                    linesEvaluated.Add(line);

                    bool isMove = false;

                    int squareCurrentPieceIsOnIndex = line.IndexOf(i);
                    int squareToMoveToIndex = BoardArray[i] == GridEntry.WHITEKING ? (bKingReverseLine ? squareCurrentPieceIsOnIndex - 1 : squareCurrentPieceIsOnIndex + 1) : squareCurrentPieceIsOnIndex + 1;
                    int captureIndexForWhiteIndex = BoardArray[i] == GridEntry.WHITEKING ? (bKingReverseLine ? squareCurrentPieceIsOnIndex - 2 : squareCurrentPieceIsOnIndex + 2) : squareCurrentPieceIsOnIndex + 2;
                    int moveSquare = 0;
                    int captureSquare = 0;
                    GridEntry staringSquare = BoardArray[i];
                    GridEntry[] newValuesForBoardArray = (GridEntry[])BoardArray.Clone();

                    if (squareToMoveToIndex >= 0 && squareToMoveToIndex < line.Count())
                    {
                        moveSquare = line[squareToMoveToIndex];
                        captureSquare = captureIndexForWhiteIndex > 0 && captureIndexForWhiteIndex < line.Count() ? line[captureIndexForWhiteIndex] : -1;

                        bool bHasCaptureSquareToLandOn = captureSquare >= 0 && BoardArray[captureSquare] == GridEntry.EMPTY;
                        bool bHasPieceThatCanBeCaptued = BoardArray[moveSquare] == GridEntry.BLACKKING || BoardArray[moveSquare] == GridEntry.BLACKPAWN;
                        bool bHasMoveThatCanBeMade = BoardArray[moveSquare] == GridEntry.EMPTY;

                        if ((bHasMoveThatCanBeMade || (bHasCaptureSquareToLandOn && bHasPieceThatCanBeCaptued)) == false)
                            continue;

                        if (BoardArray[moveSquare] == GridEntry.EMPTY)
                        {
                            newValuesForBoardArray[moveSquare] = (staringSquare == GridEntry.WHITEPAWN && (moveSquare == 56 || moveSquare == 58 || moveSquare == 60 || moveSquare == 62)) ? GridEntry.WHITEKING : staringSquare;
                            newValuesForBoardArray[i] = GridEntry.EMPTY;
                            PossibleBoards.Add(new Board(newValuesForBoardArray, !m_TurnForPlayerBlack));
                            isMove = true;
                        }

                        if (captureSquare > 0 && !isMove)
                        {
                            newValuesForBoardArray[captureSquare] = (staringSquare == GridEntry.WHITEPAWN && (moveSquare == 56 || moveSquare == 58 || moveSquare == 60 || moveSquare == 62)) ? GridEntry.WHITEKING : staringSquare;
                            newValuesForBoardArray[moveSquare] = GridEntry.EMPTY;
                            newValuesForBoardArray[i] = GridEntry.EMPTY;
                            PossibleBoards.Add(new Board(newValuesForBoardArray, !m_TurnForPlayerBlack));
                        }
                    }
                }
            }

            return PossibleBoards;
        }
 public TestPropertyDescriptorGridEntry(PropertyGrid ownerGrid, GridEntry peParent, bool hide)
     : base(ownerGrid, peParent, hide)
 {
 }
示例#17
0
 public Board(GridEntry[] valuesForBoardArray, bool turnForPlayerBlack)
 {
     m_TurnForPlayerBlack = turnForPlayerBlack;
     BoardArray = valuesForBoardArray;
     ComputerScore();
 }
 public TestGridEntry(PropertyGrid ownerGrid, GridEntry peParent, PropertyGridView propertyGridView)
     : base(ownerGrid, peParent)
 {
     _propertyGridView = propertyGridView;
 }
示例#19
0
 public override Editor GetEditor(GridEntry entry)
 {
     return(editor);
 }
示例#20
0
        private int GetScoreForOneLine(GridEntry[] values, List<int> squares)
        {
            int CountB = 0;
            int CountW = 0;
            int CountBK = 0;
            int CountWK = 0;

            //Might need to calculate each move on a line and weight them
            foreach (var v in values)
            {
                if (v == GridEntry.NULL || v == GridEntry.EMPTY)
                    continue;

                if (v == GridEntry.BLACKPAWN)
                {
                    CountB++;
                }

                if (v == GridEntry.WHITEPAWN)
                {
                    CountW++;
                }

                if (v == GridEntry.BLACKKING)
                {
                    CountB += 1;
                    CountBK += 3;
                }

                if (v == GridEntry.WHITEKING)
                {
                    CountW += 1;
                    CountWK += 3;
                }
            }

            int advantage = 3;
            int advOpp = 5;
            if (m_TurnForPlayerBlack)
            {
                int ret1 = ((int)Math.Pow(CountB, 2) + ((int)Math.Pow(CountBK, advantage))) - (CountW * advOpp);
                return ret1;
            }

            int ret2 = ((int)Math.Pow(CountW, 2) + ((int)Math.Pow(CountWK, advantage))) - (CountB * advOpp);
            return ret2;
            //return -((int)Math.Pow(CountW, 3) + (CountWK * advantage)) - CountB;;
        }
示例#21
0
 private void MenuItem_Click_3(object sender, RoutedEventArgs e)
 {
     try
     {
         OpenFileDialog dlg = new OpenFileDialog();
         dlg.DefaultExt = ".tg";
         dlg.Filter = "TestGenerator files (*.tg)|*.tg";
         dlg.ShowDialog();
         StreamReader inp;
         if (dlg.FileName != "") inp = new StreamReader(dlg.FileName);
         else return;
         TestGenFilePath = dlg.FileName;
         int count = Convert.ToInt32(inp.ReadLine());
         collection.Clear();
         for (int q = 0; q < count; q++)
         {
             GridEntry ge = new GridEntry();
             ge.type = inp.ReadLine();
             ge.dataType = inp.ReadLine();
             ge.minValue = inp.ReadLine();
             ge.maxValue = inp.ReadLine();
             ge.sizeX = inp.ReadLine();
             ge.sizeY = inp.ReadLine();
             ge.chars = inp.ReadLine();
             ge.length = inp.ReadLine();
             collection.Add(ge);
         }
         randomGrid.Items.Refresh();
         inp.Close();
     }
     catch (Exception exc)
     {
         ShowExceptionMessage();
     }
     shownThisRun = false;
 }
示例#22
0
 private void AdjustBoard(BoardLocation location, GridEntry state)
 {
     _GameTurn.BOARDARRAY[location.Row, location.Column] = (int)state;
 }