コード例 #1
0
        public MazeGenerator( int width, int height )
        {
            this.Width = width;
            this.Height = height;

            this.coordinateGrid = new Coordinate[ height, width ];
        }
コード例 #2
0
        // This method will return the current coordinate of the knight
        private Coordinate GetCurrCoordinate(Coordinate[,] coordinates)
        {
            Coordinate currCoordinate = null;

            for (int y = 0; y < coordinates.GetLength(0); y++)
            {
                for (int x = 0; x < coordinates.GetLength(1); x++)
                {
                    if (coordinates[x, y].isCurrCoor)
                    {
                        currCoordinate = coordinates[x, y];
                    }
                }
            }

            return(currCoordinate);
        }
コード例 #3
0
        /// <summary>
        /// Run the program by asking for input and computing the nearest cheapest tickets.
        /// </summary>
        public void Run()
        {
            // Fill the grid with random data
            RandomFiller rndFill = new RandomFiller(MIN_X, MAX_X, MIN_Y, MAX_Y, POINTS);

            rndFill.CreateData();
            data = rndFill.Data;

            int    x = 0, y = 0;
            string line;
            bool   condition = false;
            Regex  regex;
            Match  match, match1;

            Console.Write("\n\n\n");
            do
            {
                Console.Write("Write down your location as pair of coordinates, e.g. (4, 2) with one whitespace: ");
                line = Console.ReadLine();

                // Analyse input pattern
                regex = new Regex(@"[(]-*\d+[,]\s-*\d+[)]+");
                match = regex.Match(line);
                if (match.Success)
                {
                    // Get x and y from input coordinates
                    regex  = new Regex(@"-*\d+");
                    match1 = regex.Match(match.Value);
                    orig_x = Convert.ToInt32(Regex.Match((match1.Value), @"-*\d+").Value);
                    x      = orig_x + Math.Abs(MIN_X);

                    regex  = new Regex(@"[ ]-*\d+");
                    match1 = regex.Match(match.Value);
                    orig_y = Convert.ToInt32(match1.Value);
                    y      = orig_y + Math.Abs(MIN_Y);

                    if (orig_x >= MIN_X && orig_x <= MAX_X &&
                        orig_y >= MIN_Y && orig_y <= MAX_Y)
                    {
                        condition = true;
                    }
                }
            } while (!condition);

            FindClosestEvents(x, y);
        }
コード例 #4
0
ファイル: TetrisGrid.cs プロジェクト: Hengle/Tetris-1
    public TetrisGrid(int width, int height, int groupSize, BrickPool pool)
    {
        size = new Size(width + 1, height + 1);

        Grid = new Option <Brick> [size.width, size.height];
        InitArray(Grid);

        activeGroup = new Option <Brick> [groupSize];

        //4 because of 4 rotations
        activeShape = new Coordinate[groupSize, 4];

        //Hardcoded aproximate spawn zone location
        spawnPoint = new Coordinate((size.width - 4) / 2, size.height - 2);

        this.pool = pool;
    }
コード例 #5
0
 public static Coordinate GetStartCoordinate(Coordinate[,] coords)
 {
     for (int x = 0; x < coords.GetLength(0); x++)
     {
         for (int y = 0; y < coords.GetLength(1); y++)
         {
             {
                 Coordinate coordinate = coords[x, y];
                 if (coordinate.FloodFillStatus == Enumerations.FloodFillStatus.Suitable)
                 {
                     return(coordinate);
                 }
             }
         }
     }
     return(null);
 }
コード例 #6
0
ファイル: AI.cs プロジェクト: corysutyak/Battleship
 public Coordinate chooseMove(Board oppB, Coordinate[,] heatmap)
 {
     //random
     if (difficulty == "easy")
     {
         return(easyMove());
     }
     //hunting and targeting
     if (difficulty == "medium")
     {
         return(mediumMove(oppB));
     }
     //Heat map
     else
     {
         return(hardMove(oppB, heatmap));
     }
 }
コード例 #7
0
        private List <Coordinate> GetFlooded(Coordinate[,] coords)
        {
            List <Coordinate> floodFilled = new List <Coordinate>();

            for (int x = 0; x < coords.GetLength(0); x++)
            {
                for (int y = 0; y < coords.GetLength(1); y++)
                {
                    {
                        if (coords[x, y].FloodFillStatus == Enumerations.FloodFillStatus.Yes)
                        {
                            floodFilled.Add(coords[x, y]);
                        }
                    }
                }
            }
            return(floodFilled);
        }
コード例 #8
0
        public void Initialize()
        {
            if (_offsets == null)
            {
                _halfOffsetLength = (int)(_maxViewFieldRadius / FogOfViewField.Instance.gridHeight);
                int offsetLength = _halfOffsetLength * 2 + 1;
                _offsets = new Coordinate[offsetLength, offsetLength];
                for (int a = 0; a < offsetLength; ++a)
                {
                    for (int b = 0; b < offsetLength; ++b)
                    {
                        _offsets[a, b] = new Coordinate {
                            x = a - _halfOffsetLength, y = b - _halfOffsetLength
                        };
                    }
                }
            }

            GetCache();
        }
コード例 #9
0
        private void GetRemnantsWithinBorders(Coordinate[,] coords)
        {
            List <Coordinate> allCoords = coords.Cast <Coordinate>().ToList();

            allCoords = allCoords.FindAll(c => c.FloodFillStatus != Enumerations.FloodFillStatus.Yes);
            allCoords = allCoords.FindAll(c => c.FloodFillStatus != Enumerations.FloodFillStatus.Yes && c.X > Left && c.X <Right && c.Y> Top && c.Y < Down);
            List <Coordinate> remnants = new List <Coordinate>();

            Parallel.ForEach(allCoords, (c) =>
            {
                if (c.SomethingLeft(Flooded) && c.SomethingRight(Flooded) && c.SomethingTop(Flooded) && c.SomethingBottom(Flooded))
                {
                    coords[c.X, c.Y].FloodFillStatus = Enumerations.FloodFillStatus.Yes;
                    remnants.Add(c);
                }
            }
                             );

            Flooded.AddRange(remnants);
        }
コード例 #10
0
 public static void ResetFloodedCoords(Coordinate[,] coords, Bitmap bitmap)
 {
     for (int x = 0; x < coords.GetLength(0); x++)
     {
         for (int y = 0; y < coords.GetLength(1); y++)
         {
             Coordinate coordinate = coords[x, y];
             if (coords[x, y].FloodFillStatus == Enumerations.FloodFillStatus.Yes)
             {
                 if (IsWhite(bitmap, x, y))
                 {
                     coords[x, y].FloodFillStatus = Enumerations.FloodFillStatus.Suitable;
                 }
                 else
                 {
                     coords[x, y].FloodFillStatus = Enumerations.FloodFillStatus.NotSuitable;
                 }
             }
         }
     }
 }
コード例 #11
0
        public override bool HeuristicsPlay(Coordinate currCoordinate, Coordinate[,]
                                            coordinates, Random r)
        {
            int count = 0;
            int move, newX, newY;
            int?accessibility = null;

            ArrayList potentialCoordinates = new ArrayList();

            // Using random to generate random move, and store all possible moves for further action
            do
            {
                move = r.Next(8);
                newX = base.MovingX(move, currCoordinate.X);
                newY = base.MovingY(move, currCoordinate.Y);

                if (((newX >= 0 && newX <= 7) &&
                     (newY >= 0 && newY <= 7)) &&
                    !coordinates[newX, newY].isLanded)
                {
                    // Getting all the possible moves first
                    potentialCoordinates.Add(coordinates[newX, newY]);
                    ((Coordinate)potentialCoordinates[potentialCoordinates.Count - 1]).MoveType = move;
                }

                count++;
            } while (count < 30);

            // Going through all types of move and see if there will be any possible move
            // if the previous code block can't not genarate any possible move
            if (count > 30 || potentialCoordinates.Count == 0)
            {
                potentialCoordinates.Clear();

                for (int i = 0; i < 8; i++)
                {
                    newX = MovingX(i, currCoordinate.X);
                    newY = MovingY(i, currCoordinate.Y);

                    if (((newX >= 0 && newX <= 7) &&
                         (newY >= 0 && newY <= 7)) &&
                        !coordinates[newX, newY].isLanded)
                    {
                        potentialCoordinates.Add(coordinates[newX, newY]);
                        ((Coordinate)potentialCoordinates[potentialCoordinates.Count - 1]).MoveType = i;
                    }
                }

                if (potentialCoordinates.Count == 0)
                {
                    return(true);
                }
            }

            // Check the accessibilty of different coordinates and pick out the one with the
            // lowest accessibility
            for (int i = 0; i < potentialCoordinates.Count; i++)
            {
                if (accessibility == null ||
                    ((Coordinate)potentialCoordinates[i]).Accessibility < accessibility)
                {
                    accessibility = ((Coordinate)potentialCoordinates[i]).Accessibility;
                    newX          = ((Coordinate)potentialCoordinates[i]).X;
                    newY          = ((Coordinate)potentialCoordinates[i]).Y;
                    coordinates[newX, newY].MoveType = ((Coordinate)potentialCoordinates[i]).MoveType;
                }
            }

            currCoordinate.Leave();
            coordinates[newX, newY].Land();
            return(false);
        }
コード例 #12
0
 public abstract bool HeuristicsPlay(Coordinate currCoordinate,
                                     Coordinate[,] coordinates, Random r);
コード例 #13
0
 public abstract bool NonIntelligentPlay(Coordinate currCoordinate,
                                         Coordinate[,] coordinates, Random r);
コード例 #14
0
    void _OnBoardGenerated(BoardGeneratedEvent e)
    {
        int height = BoardData.GetHeight();
        int width  = BoardData.GetWidth();

        // num nodes = (height / 2) * (width / 2)
        int node_height = height / 2;
        int node_width  = width / 2;
        // Create MST with Kruskal's algorithm
        List <Edge> edges = new List <Edge>(); // not sorted in any order

        MstNode[, ] nodes = new MstNode[node_width, node_height];

        // populate nodes and edges
        for (int x = 0; x < node_width; ++x)
        {
            for (int y = 0; y < node_height; ++y)
            {
                nodes[x, y] = new MstNode(x, y);

                // add edge 0 if not at top of grid
                if (y < node_height - 1)
                {
                    edges.Add(new Edge(new Coordinate(x, y), 0));
                }
                // add edge 1 if not at right side of grid
                if (x < node_width - 1)
                {
                    edges.Add(new Edge(new Coordinate(x, y), 1));
                }
            }
        }
        Debug.Assert(edges.Count == (node_height * (node_width - 1) + node_width * (node_height - 1)));

        int added_edges = 0;

        while (added_edges < node_width * node_height - 1)
        {
            // select a random edge
            int        i    = Random.Range(0, edges.Count);
            Edge       edge = edges[i];
            Coordinate vertex2;
            if (edge.output_side == 0)
            {
                vertex2 = new Coordinate(edge.vertex.x, edge.vertex.y + 1);
            }
            else
            {
                vertex2 = new Coordinate(edge.vertex.x + 1, edge.vertex.y);
            }

            // remove from edges
            edges[i] = edges[edges.Count - 1];
            edges.RemoveAt(edges.Count - 1);

            // if the edge forms a cycle, discard, else, add

            // check representative
            Coordinate repA = GetRepresentative(nodes, edge.vertex);
            Coordinate repB = GetRepresentative(nodes, vertex2);

            // if reps are equal, there is a cycle (do nothing)
            // otherwise add the edges to mstTree, update representatives
            if (repA != repB)
            {
                added_edges++;

                nodes[edge.vertex.x, edge.vertex.y].nearby_edges[edge.output_side] = true;
                nodes[vertex2.x, vertex2.y].nearby_edges[edge.output_side + 2]     = true;

                nodes[repA.x, repA.y].representative = repB;
            }
        }

        // Assign paths based on MST
        next_map = new Coordinate[width, height];

        // start at lower left edge
        Coordinate current_step = new Coordinate(0, 0);

        while (current_step != new Coordinate(1, 0))
        {
            MstNode    node = nodes[current_step.x / 2, current_step.y / 2];
            Coordinate next = new Coordinate(0, 0);

            // check an edge based on position in node quadrant

            // lower left
            if (current_step.x % 2 == 0 && current_step.y % 2 == 0)
            {
                if (node.nearby_edges[3])
                {
                    next = new Coordinate(current_step.x - 1, current_step.y);
                }
                else
                {
                    next = new Coordinate(current_step.x, current_step.y + 1);
                }
            }
            // top left
            else if (current_step.x % 2 == 0 && current_step.y % 2 == 1)
            {
                if (node.nearby_edges[0])
                {
                    next = new Coordinate(current_step.x, current_step.y + 1);
                }
                else
                {
                    next = new Coordinate(current_step.x + 1, current_step.y);
                }
            }
            // top right
            else if (current_step.x % 2 == 1 && current_step.y % 2 == 1)
            {
                if (node.nearby_edges[1])
                {
                    next = new Coordinate(current_step.x + 1, current_step.y);
                }
                else
                {
                    next = new Coordinate(current_step.x, current_step.y - 1);
                }
            }
            // bottom right
            else if (current_step.x % 2 == 1 && current_step.y % 2 == 0)
            {
                if (node.nearby_edges[2])
                {
                    next = new Coordinate(current_step.x, current_step.y - 1);
                }
                else
                {
                    next = new Coordinate(current_step.x - 1, current_step.y);
                }
            }

            next_map[current_step.x, current_step.y] = next;
            current_step = next;
        }
    }
コード例 #15
0
ファイル: Map.cs プロジェクト: watermelonade/isometric-wars
    void Build()
    {
        board = new GameObject[width, height];
        distanceMap = new int[width, height];
        pathMap = new Coordinate[width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                GameObject spawn;
                switch (levelBase[y][x])
                {

                    case wallTile:
                        //spawn = Instantiate(Resources.Load("Prefabs/MapTiles/Wall", typeof(GameObject))) as GameObject;
                        board[x, y] = null;
                        //spawn.transform.position = new Vector3(x, 0.5F, y);
                        break;
                    case defaultTile:
                        spawn = Instantiate(Resources.Load("Prefabs/MapTiles/map_prefab", typeof(GameObject))) as GameObject;
                        board[x, y] = spawn;
                        spawn.transform.position = new Vector3(x, 0.5F, y);
                        break;
                }

            }
        }
    }
コード例 #16
0
        public ChunkyDataCHAN(int version_in, string name_in, byte[] innerData) : base("CHAN", version_in, name_in)
        {
            stringLength = innerData[12] + (innerData[13] << 8) + (innerData[14] << 16) + (innerData[15] << 24);

            colourMask    = new byte[4];
            colourMask[0] = innerData[8];
            colourMask[1] = innerData[9];
            colourMask[2] = innerData[10];
            colourMask[3] = innerData[11];

            if (innerData[4] == 1)
            {
                method = ChannelMethod.Texture;
            }
            else if (innerData[4] == 2)
            {
                method = ChannelMethod.Add;
            }
            else if (innerData[4] == 3)
            {
                method = ChannelMethod.Blend;
            }
            else if (innerData[4] > 3 || innerData[4] == 0)
            {
                method = ChannelMethod.None;
            }
            else
            {
                throw new InvalidChunkValueException("Invalid value found for CHAN method", "Channel Method", innerData[4]);
            }

            channel     = (ChannelType)innerData[0];
            channelName = ByteArrayToTextString(innerData, 16, stringLength);
            unknown     = new byte[4];
            unknown[0]  = innerData[stringLength + 16];
            unknown[1]  = innerData[stringLength + 17];
            unknown[2]  = innerData[stringLength + 18];
            unknown[3]  = innerData[stringLength + 19];
            int coordPos = stringLength + 20;

            numCoords   = innerData[coordPos] + (innerData[coordPos + 1] << 8) + (innerData[coordPos + 2] << 16) + (innerData[coordPos + 3] << 24);
            unknown2    = new byte[4];
            unknown2[0] = innerData[coordPos + 4];
            unknown2[1] = innerData[coordPos + 5];
            unknown2[2] = innerData[coordPos + 6];
            unknown2[3] = innerData[coordPos + 7];

            coords = new Coordinate[numCoords, 4];

            int pos = coordPos + 8;

            for (int i = 0; i < numCoords && pos < innerData.Length; i++)
            {
                coords[i, 0] = new Coordinate(ByteArrayToSingle(innerData, pos), ByteArrayToSingle(innerData, pos + 4));
                coords[i, 1] = new Coordinate(ByteArrayToSingle(innerData, pos + 8), ByteArrayToSingle(innerData, pos + 12));
                coords[i, 2] = new Coordinate(ByteArrayToSingle(innerData, pos + 16), ByteArrayToSingle(innerData, pos + 20));
                coords[i, 3] = new Coordinate(ByteArrayToSingle(innerData, pos + 24), ByteArrayToSingle(innerData, pos + 28));
                i++;
                pos = coordPos + 8 + (i * 32);
            }
        }
コード例 #17
0
    /// <summary>
    /// Given an array of tiles and a starting coordinate,
    /// find all reachable tiles (and paths to get to those tiles).
    /// This is implemented using a modified form of Djikstra's algorithm.
    /// </summary>
    /// <param name="tiles"></param>
    /// <param name="startCoord"></param>
    public static void FindReachableTiles(
        int rows,
        int cols,
        int[,] dist,
        Coordinate[,] prev,
        Tile[,] tiles,
        Coordinate startCoord,
        int movementPoints)
    {
        var frontier = new MinHeap <TileCoordinateNode>();

        TileCoordinate startTileCoordinate = new TileCoordinate(
            tiles[startCoord.r, startCoord.c],
            startCoord);

        TileCoordinateNode startNode = new TileCoordinateNode(startTileCoordinate, 0);

        frontier.Insert(startNode);

        for (int r = 0; r < rows; ++r)
        {
            for (int c = 0; c < cols; ++c)
            {
                Coordinate coord = new Coordinate(r, c);

                if (!coord.Equals(startCoord))
                {
                    dist[coord.r, coord.c] = int.MaxValue;
                    prev[coord.r, coord.c] = null;
                }
                else
                {
                    dist[coord.r, coord.c] = 0;
                    prev[coord.r, coord.c] = null; // doesn't matter for start coord
                }
            }
        }

        while (frontier.HeapSize() > 0)
        {
            TileCoordinateNode node           = frontier.Pop();
            TileCoordinate     tileCoordinate = node.tileCoordinate;
            Coordinate         coordinate     = tileCoordinate.coordinate;

            foreach (TileCoordinate adjacentTileCoord
                     in GetAdjacentTiles(tiles, coordinate))
            {
                Coordinate adjacentCoord = adjacentTileCoord.coordinate;

                // watch for overflow here
                int calculatedDist = dist[coordinate.r, coordinate.c]
                                     + adjacentTileCoord.tile.movementCost;

                bool calculatedDistPreferrable
                    = dist[adjacentCoord.r, adjacentCoord.c] == int.MaxValue ||
                      calculatedDist < dist[adjacentCoord.r, adjacentCoord.c];

                if (calculatedDistPreferrable && calculatedDist <= movementPoints)
                {
                    dist[adjacentCoord.r, adjacentCoord.c] = calculatedDist;
                    prev[adjacentCoord.r, adjacentCoord.c] = coordinate;

                    TileCoordinateNode adjacentNode
                        = new TileCoordinateNode(adjacentTileCoord, calculatedDist);

                    if (!frontier.Contains(adjacentNode))
                    {
                        frontier.Insert(adjacentNode);
                    }
                    else
                    {
                        frontier.DecreaseKey(adjacentNode, adjacentNode);
                    }
                }
            }
        }
    }
コード例 #18
0
 public abstract String IsStringExist(String inputString, Coordinate[,] coordinates);
コード例 #19
0
 void Awake()
 {
     InstanceSceneManager();
     arrayCoordinateFloor = new Coordinate[width, height];
     UnityEngine.Random.InitState((int)DateTime.Now.Ticks);
 }
コード例 #20
0
ファイル: Form_Main.cs プロジェクト: XuYan/Greedy-Snake
 void InitializeMapLayout()
 {
     this.mapLayout = MapFactory.CreateMap(ReadGameProperties(), PaintAt).Create();
 }
コード例 #21
0
        /// <summary>
        /// Finds the proper pixel locations of all entries in the text table, as well as the size that the table must be to prevent overlapping text.
        /// </summary>
        void rebuildTable()
        {
            dataPositions = new Coordinate[data.GetLength(0), data.GetLength(1)];
            //Figure out size of each piece of text
            Coordinate[,] stringSizes = new Coordinate[data.GetLength(0), data.GetLength(1)];
            //Figure out minimum size from that (widest row, number of rows * (text height + spacing))
            int tableMinX = 0;

            //Figure out the amount of space that each column needs
            int[] columnMins = new int[data.GetLength(0)];
            for (int y = 0; y < data.GetLength(1); y++)
            {
                int rowMinX = 0;
                for (int x = 0; x < data.GetLength(0); x++)
                {
                    stringSizes[x, y] = (Coordinate)ScreenManager.Globals.Fonts[this.font].MeasureString(data[x, y]);
                    rowMinX          += stringSizes[x, y].X;
                    if (stringSizes[x, y].X > columnMins[x])
                    {
                        columnMins[x] = stringSizes[x, y].X;
                    }
                }
                if (rowMinX > tableMinX)
                {
                    tableMinX = rowMinX;
                }
            }

            //Divide available x space between each column, taking into account desired fraction of available space
            int[] columnAllottedXSpace = new int[columns.Length];
            int   availableWidth       = targetArea.Width;
            float total = 0;

            for (int i = 0; i < columns.Length; i++)
            {
                total += columns[i].Spacing;
            }
            for (int i = 0; i < columns.Length; i++)
            {
                columnAllottedXSpace[i] = (int)((columns[i].Spacing / total) * availableWidth);
                //Try to prevent overlapping by stealing space from the column to follow
                if (columnAllottedXSpace[i] < columnMins[i])
                {
                    availableWidth         -= columnMins[i];
                    total                  -= columns[i].Spacing;
                    columnAllottedXSpace[i] = columnMins[i];
                }
            }

            //Place text according to column justification
            for (int y = 0; y < data.GetLength(1); y++)
            {
                int yCoord          = y * (interlineSpacing + stringSizes[0, y].Y);
                int currentleftMost = 0;
                for (int x = 0; x < data.GetLength(0); x++)
                {
                    switch (columns[x].Justified)
                    {
                    case Justification.Left:
                        dataPositions[x, y] = new Coordinate(currentleftMost, yCoord);
                        break;

                    case Justification.Middle:
                        dataPositions[x, y] = new Coordinate(currentleftMost + ((columnAllottedXSpace[x] - stringSizes[x, y].X) / 2), yCoord);
                        break;

                    case Justification.Right:
                        dataPositions[x, y] = new Coordinate((currentleftMost + columnAllottedXSpace[x]) - stringSizes[x, y].X, yCoord);
                        break;
                    }
                    currentleftMost += columnAllottedXSpace[x];
                }
            }
        }
コード例 #22
0
ファイル: BattleGround.cs プロジェクト: mtorkamani/battleship
 public BattleGround(int size)
 {
     Coordinates = new Coordinate[size, size];
     Reset();
 }
コード例 #23
0
        private void btnNextTrial_Click(object sender, EventArgs e)
        {
            if (trial < targetTrial)
            {
                count = 0;

                coordinates = InitiatingCoordinates(startX, startY);

                do
                {
                    Coordinate currCoordinate;

                    // Getting the current location of the knight
                    currCoordinate = GetCurrCoordinate(coordinates);

                    // Setting when did the knight landed at this location
                    currCoordinate.LandedTime = (count + 1);
                    if (method == 1)
                    {
                        end = control.HeuristicsPlay(currCoordinate, coordinates, r);
                    }

                    if (method == 2)
                    {
                        end = control.NonIntelligentPlay(currCoordinate, coordinates, r);
                    }

                    count++;
                } while (!end);

                lblPlayOutputTitle.Text = String.Format("Knight's movement for trial {0}:",
                                                        (trial + 1));

                trialOutput += String.Format("Trial {0}: The knight was able to " +
                                             "successfully land on {1} squares.\n", (trial + 1), count);

                chestBoardOutput = PrintPlay(coordinates);

                trialPlay[trial] = count;
                trial++;
            }

            if (trial == targetTrial)
            {
                // Getting the average plays
                sumPlay = 0;

                for (int i = 0; i < trialPlay.Length; i++)
                {
                    sumPlay += trialPlay[i];
                }

                avgPlay = Convert.ToDouble(sumPlay) / Convert.ToDouble(trialPlay.Length);


                // Getting the standard deviation
                SD = 0;

                for (int i = 0; i < trialPlay.Length; i++)
                {
                    SD += Math.Pow((Convert.ToDouble(trialPlay[i]) - avgPlay), 2);
                }

                SD /= trialPlay.Length;
                SD  = Math.Sqrt(SD);

                trialOutput += String.Format("\nThe average landing times is: {0}\n" +
                                             "Standard deviation is: {1}\n",
                                             Math.Floor(avgPlay), SD);

                btnNextTrial.Enabled = false;

                if (method == 1)
                {
                    if (!File.Exists("TszKinYeung_HeuristicsMethod.txt"))
                    {
                        file = File.CreateText("TszKinYeung_HeuristicsMethod.txt");
                    }
                    else
                    {
                        file = File.AppendText("TszKinYeung_HeuristicsMethod.txt");
                    }
                }
                if (method == 2)
                {
                    if (!File.Exists("TszKinYeung_NonIntelligentMethod.txt"))
                    {
                        file = File.CreateText("TszKinYeung_NonIntelligentMethod.txt");
                    }
                    else
                    {
                        file = File.AppendText("TszKinYeung_NonIntelligentMethod.txt");
                    }
                }

                file.WriteLine(trialOutput);
                file.WriteLine("------------------------------------------------------------------\n");
                file.Close();
            }


            lblPlayOutput.Text            = chestBoardOutput;
            rtbTrialOutput.Text           = trialOutput;
            rtbTrialOutput.SelectionStart = rtbTrialOutput.Text.Length;
            rtbTrialOutput.ScrollToCaret();
        }
コード例 #24
0
        public override String IsStringExist(String inputString, Coordinate[,] coordinates)
        {
            int stringIndex = 0;

            char[] inputStringArray = inputString.ToCharArray();
            String charPositions    = "";

            for (int x = 0; x < coordinates.GetLength(0) && stringIndex != (inputStringArray.Length - 1); x++)
            {
                for (int y = 0; y < coordinates.GetLength(1) && stringIndex != (inputStringArray.Length - 1); y++)
                {
                    if (inputStringArray[stringIndex] == coordinates[x, y].Character)
                    {
                        for (int direction = 0; direction < 8 && stringIndex != (inputStringArray.Length - 1); direction++)
                        {
                            charPositions = "";
                            stringIndex   = 0;
                            int newX = base.GetNextX(direction, x);
                            int newY = base.GetNextY(direction, y);
                            // This string will tell user where are the characters, and store the position
                            // of the first matching character
                            charPositions += String.Format("{0}: (x: {1}, y: {2}); ", coordinates[x, y].Character, x, y);

                            do
                            {
                                // check if the character in the next coordinate matches the next character in string
                                if (newX >= 0 && newX <= (coordinates.GetLength(0) - 1) &&
                                    newY >= 0 && newY <= (coordinates.GetLength(1) - 1) &&
                                    coordinates[newX, newY].Character == inputStringArray[stringIndex + 1] &&
                                    stringIndex != (inputStringArray.Length - 1))
                                {
                                    // if the character in the next coordinate matches the next character in string,
                                    // get the next coordinate with the same direction and loop through
                                    stringIndex++;
                                    charPositions += String.Format("{0}: (x: {1}, y: {2}); ",
                                                                   coordinates[newX, newY].Character, newX, newY);
                                    // only perfrom the following if statement when the cursor isn't
                                    // at the end of the user input
                                    if (stringIndex != (inputStringArray.Length - 1))
                                    {
                                        newX = base.GetNextX(direction, newX);
                                        if (newX < 0 || newX >= coordinates.GetLength(0))
                                        {
                                            break;
                                        }
                                        else
                                        {
                                            newY = base.GetNextY(direction, newY);
                                        }
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            } while (stringIndex != (inputStringArray.Length - 1));
                        }
                    }
                }
            }

            if (stringIndex != (inputStringArray.Length - 1))
            {
                return("\"" + inputString + "\" is not found");
            }
            else
            {
                return("\"" + inputString + "\" is found at:\n" + charPositions);
            }
        }
コード例 #25
0
ファイル: Mesh.cs プロジェクト: robojames/TEModel
        public void Generate_Coordinate_Pairs()
        {
            CV_Coordinates = new List<Coordinate>();

            int n_Coordinate_Pairs = 0;

            foreach (double x_pos in Modified_X_Distinct)
            {
                foreach (double y_pos in Modified_Y_Distinct)
                {
                    CV_Coordinates.Add(new Coordinate(x_pos, y_pos, n_Coordinate_Pairs));
                    n_Coordinate_Pairs++;
                }
            }

            Console.WriteLine("Coordinate Pairs Generated:  " + n_Coordinate_Pairs.ToString());

            var Sorted_Coordinate_Pairs = CV_Coordinates.OrderBy(Coord => Coord.X).ThenBy(Coord => Coord.Y).ToList().GroupBy(Coord => Coord.X).ToList();

            Coordinate[,] Temp_Array_of_Coordinates = ListtoJaggedArray(Sorted_Coordinate_Pairs);

            Coordinate_Array = Temp_Array_of_Coordinates;
        }
コード例 #26
0
 private void ResetSubwayGrid()
 {
     closestSubway = new Coordinate[data.numBlocks, data.numBlocks];
     visited       = new bool[data.numBlocks, data.numBlocks];
     subwayPaths   = new Dictionary <Coordinate, Path>();
 }