Пример #1
0
        public static TreeNode BuildTree(Color[,] board)
        {
            MapNode head = BuildMap(board);
            TreeNode root = new TreeNode(null, head.Color);

            Queue<MapTreeKeyValuePair> frontLine = new Queue<MapTreeKeyValuePair>();
            ISet<MapNode> visited = new HashSet<MapNode>();
            frontLine.Enqueue(new MapTreeKeyValuePair{MapNode = head, TreeNode = root});
            visited.Add(head);

            while (frontLine.Count > 0)
            {
                MapTreeKeyValuePair mapTree = frontLine.Dequeue();
                foreach (MapNode neighbor in mapTree.MapNode.GetNeighbors())
                {
                    if(!visited.Contains(neighbor))
                    {
                        TreeNode childTreeNode = new TreeNode(mapTree.TreeNode, neighbor.Color);
                        //Claim this map node as your child
                        mapTree.TreeNode.AddChildern(childTreeNode);
                        //mark map node as visited, no one can claim this map node again
                        visited.Add(neighbor);
                        //queue it up to find it's children
                        frontLine.Enqueue(new MapTreeKeyValuePair { MapNode = neighbor, TreeNode = childTreeNode });
                    }
                }
            }

            return root;
        }
Пример #2
0
 public BattleController()
 {
     _playerParty = new List<BattleObject>();
     _enemyParty = new List<BattleObject>();
     _activeBattleObjectsToProcess = new Queue<BattleObject>();
     _processedPressedKeys = new List<Keys>();
 }
Пример #3
0
 public Game(List<Character> fullList, outputFunction outputFunction, cleverOutput cleverOutputFunction, Rules rules)
 {
     this.fullList = fullList;
     this.characterQueue = initiateQueue();
     this.Output = outputFunction;
     this.cleverOutput = cleverOutputFunction;
     this.rules = rules;
 }
Пример #4
0
        /// <summary>
        /// Runs the main loop of the game. 
        /// It will run until one team is dead.
        /// </summary>
        public void Run()
        {
            Tuple<bool, string> characterCheck = IsCharacterOk(rules, fullList);
            Tuple<bool, string> abilityCheck = IsAbilityOk(rules, fullList);
            if (characterCheck.Item1 && abilityCheck.Item1)
            {
                Queue<Character> characterQueueTwo = new Queue<Character>();
                List<Character> teamOne, teamTwo;
                teamOne = characterQueue.Where(x => x.CharBase.Team == characterQueue.First().CharBase.Team).ToList();
                teamTwo = characterQueue.Where(x => x.CharBase.Team != teamOne.First().CharBase.Team).ToList();

                foreach (Character Char in fullList)
                    foreach (Ability Abil in Char.CharBase.Abilities)
                        Abil.OnAbilityFired += OnAbilityFired;

                bool team1turn = true;
                int turn = 1;
#if DEBUG
                while (turn < 20)
#else
            while (true)
#endif
                {
                    if (team1turn)
                    {
                        RunRound(characterQueue, characterQueueTwo, turn);
                        team1turn = false;
                    }
                    else
                    {
                        RunRound(characterQueueTwo, characterQueue, turn);
                        team1turn = true;
                    }
                    turn++;

                    #region see if there's a winner
                    if (isTeamDead(teamOne))
                    {
                        Output("Team " + teamTwo.First().CharBase.Team.ToString() + " has won the fight!");
                        break;
                    }
                    else if (isTeamDead(teamTwo))
                    {
                        Output("Team " + teamOne.First().CharBase.Team.ToString() + " has won the fight!");
                        break;
                    }
                    #endregion

                }
            }
            else
            {
                msg.Add(characterCheck.Item2, Color.Red);
                msg.Add(abilityCheck.Item2, Color.Red);
                cleverOutput(msg);
            }

        }
        public SimilarArtistController(SimilarArtistView view)
        {
            model = new LastFMModel();
            itunes = new iTunesAppClass();
            libraryPlaylist = itunes.LibraryPlaylist;

            similarArtists = new Queue<string>();
            artistTrackCount = new Dictionary<string, int>();
            artistTracks = new Dictionary<string, Queue<string>>();
            missingTracks = new List<string>();

            playlistSize = 0;

            this.view = view;
        }
Пример #6
0
        private void AvoidObstacles()
        {
            const int mapBorderWidth = 4;
            int horLength = map.GetLength(0);
            int vertLength = map.GetLength(1);
            Point currentPosition = Point.Empty;
            Point destination = Point.Empty;
            for (int i = 0; i < horLength; i++)
            {
                for (int j = 0; j < vertLength; j++)
                {
                    if (this.mapWithIdealPath[i, j] == MyRoadType.CurrentPosition)
                    {
                        currentPosition = new Point(i, j);
                    }

                    if (this.mapWithIdealPath[i, j] == MyRoadType.Destination)
                    {
                        destination = new Point(i, j);
                    }
                }
            }

            bool[,] whatBecameIdeal = new bool[horLength, vertLength];
            Action<int, int> makeAllSimilarIdeal = (x, y) =>
            {
                if (x > 0 && y > 0 && this.map[x - 1, y - 1] == MyTileType.Green
                    && this.mapWithIdealPath[x - 1, y - 1] == MyRoadType.Empty
                    && !whatBecameIdeal[x - 1, y - 1])
                {
                    whatBecameIdeal[x - 1, y - 1] = true;
                }

                if (y > 0 && this.map[x, y - 1] == MyTileType.Green
                    && this.mapWithIdealPath[x, y - 1] == MyRoadType.Empty
                    && !whatBecameIdeal[x, y - 1])
                {
                    whatBecameIdeal[x, y - 1] = true;
                }

                if (x < horLength - 1 && y > 0 && this.map[x + 1, y - 1] == MyTileType.Green
                    && this.mapWithIdealPath[x + 1, y - 1] == MyRoadType.Empty
                    && !whatBecameIdeal[x + 1, y - 1])
                {
                    whatBecameIdeal[x + 1, y - 1] = true;
                }

                if (x > 0 && this.map[x - 1, y] == MyTileType.Green
                    && this.mapWithIdealPath[x - 1, y] == MyRoadType.Empty
                    && !whatBecameIdeal[x - 1, y])
                {
                    whatBecameIdeal[x - 1, y] = true;
                }

                if (x < horLength - 1 && this.map[x + 1, y] == MyTileType.Green
                    && this.mapWithIdealPath[x + 1, y] == MyRoadType.Empty
                    && !whatBecameIdeal[x + 1, y])
                {
                    whatBecameIdeal[x + 1, y] = true;
                }

                if (x > 0 && y < vertLength - 1 && this.map[x - 1, y + 1] == MyTileType.Green
                    && this.mapWithIdealPath[x - 1, y + 1] == MyRoadType.Empty
                    && !whatBecameIdeal[x - 1, y + 1])
                {
                    whatBecameIdeal[x - 1, y + 1] = true;
                }

                if (y < vertLength - 1 && this.map[x, y + 1] == MyTileType.Green
                    && this.mapWithIdealPath[x, y + 1] == MyRoadType.Empty
                    && !whatBecameIdeal[x, y + 1])
                {
                    whatBecameIdeal[x, y + 1] = true;
                }

                if (x < horLength - 1 && y < vertLength - 1 && this.map[x + 1, y + 1] == MyTileType.Green
                    && this.mapWithIdealPath[x + 1, y + 1] == MyRoadType.Empty
                    && !whatBecameIdeal[x + 1, y + 1])
                {
                    whatBecameIdeal[x + 1, y + 1] = true;
                }
            };

            bool[,] handledReds = new bool[horLength, vertLength];
            bool verticalRoad = Math.Abs(currentPosition.Y - destination.Y)
                                > Math.Abs(currentPosition.X - destination.X);
            while (true)
            {
                bool[,] newReds = new bool[horLength, vertLength];
                bool badTileFound = false;
                Point firstBad = Point.Empty;
                for (int i = mapBorderWidth; i < horLength - mapBorderWidth && !badTileFound; i++)
                {
                    for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                    {
                        if (this.mapWithIdealPath[i, j] != MyRoadType.Empty && map[i, j] == MyTileType.Red && !handledReds[i, j])
                        {
                            badTileFound = true;
                            firstBad.X = i;
                            firstBad.Y = j;
                            break;
                        }
                    }
                }

                if (!badTileFound)
                {
                    break;
                }

                Queue<Point> badPoints = new Queue<Point>();
                badPoints.Enqueue(firstBad);
                while (badPoints.Count > 0)
                {
                    Point bad = badPoints.Dequeue();
                    if (!newReds[bad.X, bad.Y])
                    {
                        if (Math.Abs(bad.X - firstBad.X) > 80 || Math.Abs(bad.Y - firstBad.Y) > 80)
                        {
                            continue;
                        }

                        newReds[bad.X, bad.Y] = true;
                        handledReds[bad.X, bad.Y] = true;
                        if (bad.X > mapBorderWidth && bad.Y >= mapBorderWidth && bad.X < horLength - mapBorderWidth
                            && bad.Y < vertLength - mapBorderWidth && this.map[bad.X - 1, bad.Y] == MyTileType.Red
                            && !newReds[bad.X - 1, bad.Y])
                        {
                            badPoints.Enqueue(new Point(bad.X - 1, bad.Y));
                        }

                        if (bad.X < horLength - 1 - mapBorderWidth && bad.X >= mapBorderWidth && bad.Y >= mapBorderWidth
                            && bad.Y < vertLength - mapBorderWidth && this.map[bad.X + 1, bad.Y] == MyTileType.Red
                            && !newReds[bad.X + 1, bad.Y])
                        {
                            badPoints.Enqueue(new Point(bad.X + 1, bad.Y));
                        }

                        if (bad.Y > mapBorderWidth && bad.X >= mapBorderWidth && bad.X < horLength - mapBorderWidth
                            && bad.Y < vertLength - mapBorderWidth && this.map[bad.X, bad.Y - 1] == MyTileType.Red
                            && !newReds[bad.X, bad.Y - 1])
                        {
                            badPoints.Enqueue(new Point(bad.X, bad.Y - 1));
                        }

                        if (bad.Y < vertLength - 1 - mapBorderWidth && bad.Y >= mapBorderWidth && bad.X >= mapBorderWidth
                            && bad.X < horLength - mapBorderWidth && this.map[bad.X, bad.Y + 1] == MyTileType.Red
                            && !newReds[bad.X, bad.Y + 1])
                        {
                            badPoints.Enqueue(new Point(bad.X, bad.Y + 1));
                        }
                    }
                }

                if (verticalRoad)
                {
                    int maxLeft = 0, maxRight = 0;
                    for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                    {
                        int idealX = -1;
                        int correction = 0;
                        for (int i = mapBorderWidth; i < horLength - mapBorderWidth; i++)
                        {
                            if (this.mapWithIdealPath[i, j] != MyRoadType.Empty)
                            {
                                idealX = i;
                                break;
                            }
                        }

                        if (idealX == -1)
                        {
                            if (Math.Abs(j - currentPosition.Y) < Math.Abs(j - destination.Y))
                            {
                                idealX = currentPosition.X;
                                correction = Math.Abs(j - currentPosition.Y);
                            }
                            else
                            {
                                idealX = destination.X;
                                correction = Math.Abs(j - destination.Y);
                            }
                        }

                        for (int i = mapBorderWidth; i < horLength - mapBorderWidth; i++)
                        {
                            if (newReds[i, j])
                            {
                                if (i < idealX)
                                {
                                    maxLeft = Math.Max(maxLeft, idealX - i + correction);
                                }
                                else if (i > idealX)
                                {
                                    maxRight = Math.Max(maxRight, i - idealX + correction);
                                }
                            }
                        }
                    }

                    for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                    {
                        int idealX = -1;
                        for (int i = mapBorderWidth; i < horLength - mapBorderWidth; i++)
                        {
                            if (this.mapWithIdealPath[i, j] != MyRoadType.Empty)
                            {
                                idealX = i;
                                break;
                            }
                        }

                        if (idealX == -1)
                        {
                            idealX = Math.Abs(j - currentPosition.Y) < Math.Abs(j - destination.Y)
                                         ? currentPosition.X
                                         : destination.X;
                        }

                        for (int i = mapBorderWidth; i < horLength - mapBorderWidth; i++)
                        {
                            if (newReds[i, j])
                            {
                                if (i < idealX && maxLeft <= maxRight)
                                {
                                    makeAllSimilarIdeal(i, j);
                                }
                                else if (i > idealX && maxLeft > maxRight)
                                {
                                    makeAllSimilarIdeal(i, j);
                                }
                            }
                        }
                    }
                }
                else
                {
                    int maxTop = 0, maxBottom = 0;
                    for (int i = mapBorderWidth; i < horLength - mapBorderWidth; i++)
                    {
                        int idealY = -1;
                        int correction = 0;
                        for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                        {
                            if (this.mapWithIdealPath[i, j] != MyRoadType.Empty)
                            {
                                idealY = j;
                                break;
                            }
                        }

                        if (idealY == -1)
                        {
                            if (Math.Abs(i - currentPosition.X) < Math.Abs(i - destination.X))
                            {
                                idealY = currentPosition.Y;
                                correction = Math.Abs(i - currentPosition.X);
                            }
                            else
                            {
                                idealY = destination.Y;
                                correction = Math.Abs(i - destination.X);
                            }
                        }

                        for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                        {
                            if (newReds[i, j])
                            {
                                if (j < idealY)
                                {
                                    maxTop = Math.Max(maxTop, idealY - j + correction);
                                }
                                else if (j > idealY)
                                {
                                    maxBottom = Math.Max(maxBottom, j - idealY + correction);
                                }
                            }
                        }
                    }

                    for (int i = mapBorderWidth; i < horLength - mapBorderWidth; i++)
                    {
                        int idealY = -1;
                        for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                        {
                            if (this.mapWithIdealPath[i, j] != MyRoadType.Empty)
                            {
                                idealY = j;
                                break;
                            }
                        }

                        if (idealY == -1)
                        {
                            idealY = Math.Abs(i - currentPosition.X) < Math.Abs(i - destination.X)
                                         ? currentPosition.Y
                                         : destination.Y;
                        }

                        for (int j = mapBorderWidth; j < vertLength - mapBorderWidth; j++)
                        {
                            if (newReds[i, j])
                            {
                                if (j < idealY && maxTop <= maxBottom)
                                {
                                    makeAllSimilarIdeal(i, j);
                                }
                                else if (j > idealY && maxTop > maxBottom)
                                {
                                    makeAllSimilarIdeal(i, j);
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < horLength; i++)
            {
                for (int j = 0; j < vertLength; j++)
                {
                    if (this.map[i, j] == MyTileType.Red && this.mapWithIdealPath[i, j] == MyRoadType.IdealPath)
                    {
                        makeAllSimilarIdeal(i, j);
                        this.mapWithIdealPath[i, j] = MyRoadType.Empty;
                    }
                }
            }

            for (int i = 0; i < horLength; i++)
            {
                for (int j = 0; j < vertLength; j++)
                {
                    if (whatBecameIdeal[i, j])
                    {
                        this.mapWithIdealPath[i, j] = MyRoadType.IdealPath;
                    }
                }
            }
        }
Пример #7
0
        public void Listas()
        {
            List<Produto> produtos = new List<Produto>();

            var produto = new Produto
            {
                Nome = "Xbox One"
            };

            produtos.Add(produto);
            produtos.Add(produto);

            Assert.AreEqual(2, produtos.Count);

            HashSet<Produto> produtosUnicos = new HashSet<Produto>();

            produtosUnicos.Add(produto);
            produtosUnicos.Add(produto);

            Assert.AreEqual(1, produtosUnicos.Count);

            Stack<Produto> pilha = new Stack<Produto>();

            var produto2 = new Produto
            {
                Nome = "PS4"
            };

            pilha.Push(produto);
            pilha.Push(produto2);

            var produtoPeek = pilha.Peek();
            var produtoPop = pilha.Pop();
            var produtoPop2 = pilha.Pop();

            if (pilha.Any())
            {
                produtoPeek = pilha.Peek();
            }

            Queue<Produto> fila = new Queue<Produto>();

            fila.Enqueue(produto);
            fila.Enqueue(produto2);

            var primeiroDaFila = fila.Peek();
            primeiroDaFila = fila.Dequeue();

            Console.WriteLine(primeiroDaFila);

            var dic = new Dictionary<int, Produto>();

            dic.Add(50, produto);
            dic.Add(90, produto2);

            Console.WriteLine(dic[50]);
            Console.WriteLine(dic[90]);

            if (dic.ContainsKey(5))
            {
                Console.WriteLine(dic[5]);
            }
            else
            {
                dic[5] = produto;

                Console.WriteLine(dic[5]);
            }
        }
Пример #8
0
 public Auction()
 {
     auctionItems = new Queue<AuctionItem>();
 }
Пример #9
0
		/// <summary>
		///     Pass in a Queue object to update that object to the latest values
		/// </summary>
		/// <param name="queue">A current constructed queue</param>
		/// <returns>An new or updated queue</returns>
		public void UpdateQueue(Queue queue)
		{
			queue.ApiPaused = "True";
			queue.KbPerSecond = 555.55m;
		}
Пример #10
0
 /// <summary>
 /// Initialize Log instance
 /// </summary>
 private void Initialize()
 {
     _state = true;
     string logPath = System.Configuration.ConfigurationManager.AppSettings["LogDirectory"];
     _logDirectory = string.IsNullOrEmpty(logPath) ? CommonUnitlHelp.LogPathTags : logPath;
     CheckLogDirectory();
     _logType = LogType.Daily;
     _lockObject = new object();
     _semaphore = new Semaphore(0, int.MaxValue, CommonConstants.LogSemaphoreNameTags);
     _logMessages = new Queue<LogMessage>();
     var thread = new Thread(Work) { IsBackground = true };
     thread.Start();
 }
Пример #11
0
 public Competition()
 {
     Participants = new List <IParticipant>();
     Tracks       = new Queue <Track>();
 }
Пример #12
0
        //generate data for iteration 3 scenario 1
        public void createIteration3Patients(
            int patientCount_in, 
            int safePatientsNeeded_in,
            int safenessThreshold_in,
            List<GenerationRule> generationRules_in)
        {
            int patientCount = patientCount_in;
            int safePatientsNeeded = safePatientsNeeded_in;
            int patientsInserted = 0;
            int safenessThreshold = safenessThreshold_in;
            Queue<GenerationRule> generationRules = new Queue<GenerationRule>(generationRules_in);
            GenerationRule currentRule = generationRules.Dequeue();
            Random r = new Random();
            List<Visit> safeVisitsBuffer = new List<Visit>();
            DbMethods db = DbMethods.getInstance();
            int counter = 0;

            db.clearTables();

            while (patientsInserted < patientCount)
            {
                if (currentRule.PatientsLeft == 0)
                {
                    currentRule = generationRules.Dequeue();
                }

                db.InsertPatient();
                int patientID = patientsInserted;//db.InsertPatient();
                int visitsLeft = currentRule.VisitsAllowed;

                //adding safe visits
                if (safePatientsNeeded >= 0)
                {
                    if (patientsInserted % (safenessThreshold+1) == 0)
                    {
                        safeVisitsBuffer = new List<Visit>();

                        while(visitsLeft > 0)
                        {
                            safeVisitsBuffer.Add(new Visit(-1, r.Next(1, 10), r.Next(1, 6), new DateTime(2012, r.Next(1, 13), r.Next(1, 29))));
                            visitsLeft--;
                        }
                    }

                    db.InsertVisits(new Dictionary<int, List<Visit>>() { { patientID, safeVisitsBuffer } });
                    safePatientsNeeded--;
                }
                else
                {
                    while (visitsLeft > 0)
                    {
                        db.InsertVisit(patientID, r.Next(1, 10), r.Next(1, 6), new DateTime(2012, r.Next(1, 13), r.Next(1, 29)));
                        visitsLeft--;
                    }
                }

                currentRule.PatientsLeft--;
                patientsInserted++;
            }
        }
Пример #13
0
        /// <summary>
        /// Takes the full list of characters in the game, and creates a queue where the turn is alternated between two teams.
        /// </summary>
        /// <param name="fullList">The full list of characters in this class</param>
        public Queue<Character> initiateQueue()
        {

            Queue<Character> tmpQueue = new Queue<Character>();
            List<Character> teamOne = fullList.Where(x => x.CharBase.Team == fullList.First().CharBase.Team).ToList();
            List<Character> teamTwo = fullList.Where(x => x.CharBase.Team != teamOne.First().CharBase.Team).ToList();

            for (int i = 0; i < fullList.Count; i++)
            {

                if (i < teamOne.Count)
                {
                    teamOne[i].CharBase.Alive = true;
                    tmpQueue.Enqueue(teamOne[i]);
                }

                if (i < teamTwo.Count)
                {
                    teamTwo[i].CharBase.Alive = true;
                    tmpQueue.Enqueue(teamTwo[i]);
                }

            }

            return tmpQueue;
        }
Пример #14
0
        private void RunRound(Queue<Character> currentQueue, Queue<Character> nextQueue, int turn)
        {
            Output("Round: " + turn);

            while (currentQueue.Count > 0)
            {
                Character currentCharacter = currentQueue.FirstOrDefault();
                if (currentCharacter.CharBase.Alive)
                    currentCharacter.CharAI.DoTurn(fullList);
                else
                {
                    msg.Add(currentCharacter.CharBase.Name, Color.Red);
                    msg.Add(" remains dead..", Color.Black);
                    cleverOutput(msg);
                }

                nextQueue.Enqueue(currentQueue.Dequeue());
            }
        }
Пример #15
0
 /// <summary>
 /// Initialize Log instance
 /// </summary>
 private void Initialize()
 {
     _state = true;
     _lockObject = new object();
     _semaphore = new Semaphore(0, int.MaxValue, CommonConstants.MailSemaphoreNameTags);
     _mailMessages = new Queue<MailMessageModel>();
     var thread = new Thread(Work) { IsBackground = true };
     thread.Start();
 }