Esempio n. 1
0
        public static HOHPuzzle getPuzzleFromCSVLine(string csvLine)
        {
            if (csvLine.Trim().CompareTo("") == 0)
                return null;

            HOHPuzzle newPuzzle = null;
            ArrayList alResult = CSVParser.parseCSVLine(csvLine.Trim());

            //is it header line?
            if (string.Join("+", (string[])alResult.ToArray(typeof(string))).CompareTo(string.Join("+", (string[])CSVParser.parseCSVLine(getCSVHeaderLine().Trim()).ToArray(typeof(string)))) == 0)
                return null;

            if (alResult.Count >= (HOHPuzzle.csvLine.Length - HOHPuzzle.csvLine.Replace("{", "").Length))
            {
                try
                {
                    newPuzzle = new HOHPuzzle();
                    newPuzzle.standpoint = alResult[0].ToString().Trim().ToUpper();
                    newPuzzle.id = alResult[1].ToString().Trim().ToUpper();
                    newPuzzle.name = alResult[2].ToString();
                    newPuzzle.solution = alResult[3].ToString().Trim().ToUpper();
                    newPuzzle.points = (decimal)Convert.ToDecimal(alResult[4].ToString().Trim());
                    newPuzzle.pointMultipliersForPlaces = alResult[5].ToString().Trim();
                    newPuzzle.pointMultiplierForHint = (decimal)Convert.ToDecimal(alResult[6].ToString().Trim());
                    newPuzzle.hint = alResult[7].ToString().Trim();
                    newPuzzle.sendPlaceOnAnswer = (Convert.ToDecimal(alResult[8].ToString().Trim()) != 0M);
                }
                catch { return null; }
            }

            return newPuzzle;
        }
Esempio n. 2
0
        private decimal calculatePointsForTeamAtPuzzle(HOHTeam team, HOHPuzzle puzzle)
        {
            HOHPuzzle firstPuzzle = null;
            foreach (HOHEvent oneEvent in team.events)
            {
                if (oneEvent.eventType == HOHEvent.HOHEventType.SolutionEventType || oneEvent.eventType == HOHEvent.HOHEventType.HintReplyEventType)
                    if (oneEvent.puzzle.standpoint == puzzle.standpoint) {
                        firstPuzzle = oneEvent.puzzle;
                        break;
                    }
            }
            if (firstPuzzle == null)
                return 0;

            decimal points = 0;
            bool hintHasBeenTaken = false;
            bool answered = false;
            foreach (HOHEvent oneEvent in team.events)
            {
                if (!(oneEvent.eventType == HOHEvent.HOHEventType.SolutionEventType) && !(oneEvent.eventType == HOHEvent.HOHEventType.HintReplyEventType))
                    continue;
                if (oneEvent.puzzle != puzzle || oneEvent.puzzle != firstPuzzle)
                    continue;
                /*
                 ODP SPR NAP KOEF
                 1   1   1   0,5
                 1   1   0   BON
                 1   0   1   -1
                 1   0   0   -0,5
                 0   0   1   -0,5
                 0   0   0   0

                 */
                if (oneEvent.eventType == HOHEvent.HOHEventType.SolutionEventType)
                {
                    answered = true;
                    if (oneEvent.hasCorrectSolution())
                    {
                        if (hintHasBeenTaken)
                            points += puzzle.points * puzzle.pointMultiplierForHint;
                        else
                            points += puzzle.points * puzzle.getPointMultipierForPlace(getCorrectPlaceForTeamAtPuzzle(team, puzzle));
                    }
                    else
                    {
                        if (hintHasBeenTaken)
                            points -= puzzle.points * 1;
                        else
                            points -= puzzle.points * puzzle.pointMultiplierForHint;
                    }
                    break;
                }
                if (oneEvent.eventType == HOHEvent.HOHEventType.HintReplyEventType)
                    hintHasBeenTaken = true;
            }
            if (hintHasBeenTaken && !answered)
                points -= puzzle.points * puzzle.pointMultiplierForHint;

            return points;
        }
Esempio n. 3
0
        public int getCorrectPlaceForTeamAtPuzzle(HOHTeam team, HOHPuzzle puzzle)
        {
            if (!correctPlaceForTeamAtPuzzle.ContainsKey(team))
            {
                correctPlaceForTeamAtPuzzle.Add(team, new Dictionary<HOHPuzzle, int>());
            }

            if (!correctPlaceForTeamAtPuzzle[team].ContainsKey(puzzle))
            {
                int place = calculatePlaceForTeamAtPuzzle(team, puzzle, true);
                correctPlaceForTeamAtPuzzle[team].Add(puzzle, place);
                return place;
            }
            else
            {
                return correctPlaceForTeamAtPuzzle[team][puzzle];
            }
        }
Esempio n. 4
0
 private int calculateHintsTakenForTeamAtPuzzle(HOHTeam team, HOHPuzzle puzzle)
 {
     foreach (HOHEvent oneEvent in team.events) {
     if (oneEvent.eventType == HOHEvent.HOHEventType.StandingsReplyEventType)
         return 1;
     }
     return 0;
 }
Esempio n. 5
0
        private int calculatePlaceForTeamAtPuzzle(HOHTeam team, HOHPuzzle puzzle, bool correctSolutionsOnly)
        {
            Dictionary<HOHTeam, int> arriveTimeAtPuzzle = new Dictionary<HOHTeam, int>();
            foreach (HOHEvent oneEvent in puzzle.events)
            {
                if (oneEvent.eventType == HOHEvent.HOHEventType.SolutionEventType && (!correctSolutionsOnly || oneEvent.hasCorrectSolution()) && !arriveTimeAtPuzzle.ContainsKey(oneEvent.team))
                {
                    arriveTimeAtPuzzle.Add(oneEvent.team, (int)oneEvent.dateTime.Subtract(oneEvent.team.startTime).TotalSeconds);
                }
            }

            if (arriveTimeAtPuzzle.ContainsKey(team))
            {

                List<KeyValuePair<HOHTeam, int>> sortedTimes = new List<KeyValuePair<HOHTeam, int>>(arriveTimeAtPuzzle);

                sortedTimes.Sort(
                      delegate(KeyValuePair<HOHTeam, int> firstPair, KeyValuePair<HOHTeam, int> nextPair)
                      {
                          return firstPair.Value.CompareTo(nextPair.Value);
                      }
                );

                return sortedTimes.IndexOf(new KeyValuePair<HOHTeam, int>(team, arriveTimeAtPuzzle[team])) + 1;
            }
            else
            {
                return arriveTimeAtPuzzle.Count + 2;
            }
        }
Esempio n. 6
0
        internal decimal getPointsForTeamAtPuzzle(HOHTeam team, HOHPuzzle puzzle)
        {
            if (!pointsForTeamAtPuzzle.ContainsKey(team))
            {
                pointsForTeamAtPuzzle.Add(team, new Dictionary<HOHPuzzle, decimal>());
            }

            if (!pointsForTeamAtPuzzle[team].ContainsKey(puzzle))
            {
                decimal points = calculatePointsForTeamAtPuzzle(team, puzzle);
                pointsForTeamAtPuzzle[team].Add(puzzle, points);
                return points;
            }
            else
            {
                return pointsForTeamAtPuzzle[team][puzzle];
            }
        }
Esempio n. 7
0
        internal int getHintsTakenForTeamAtPuzzle(HOHTeam team, HOHPuzzle puzzle)
        {
            if (!hintsTakenForTeamAtPuzzle.ContainsKey(team))
            {
            hintsTakenForTeamAtPuzzle.Add(team, new Dictionary<HOHPuzzle, int>());
            }

            if (!hintsTakenForTeamAtPuzzle[team].ContainsKey(puzzle))
            {
            int hintCount = calculateHintsTakenForTeamAtPuzzle(team, puzzle);
            hintsTakenForTeamAtPuzzle[team].Add(puzzle, hintCount);
            return hintCount;
            }
            else
            {
            return hintsTakenForTeamAtPuzzle[team][puzzle];
            }
        }
Esempio n. 8
0
        internal void sendSmsStandingsForTeamAndPuzzle(HOHTeam team, HOHPuzzle puzzle, string phoneNumber, bool live)
        {
            if (puzzle == null || team == null) return;

            int place = this.dataManager.gameModel.getPlaceForTeamAtPuzzle(team, puzzle);

            string smsText = String.Format("Vase poradi na sifre {0}: {1}.", puzzle.name, place);
            /* TODO
            if (place > 0)
                smsText += String.Format(" Pred vami: {0}", dataManager.gameModel.);
            if (place > 1)
                smsText += String.Format(" Prvni na sifre: {0}", dataManager.gameModel.);
            */

            HOHEvent newEvent = new HOHEvent(HOHEvent.HOHEventType.StandingsReplyEventType);
            newEvent.team = team;
            newEvent.puzzle = puzzle;
            newEvent.phoneNumber = phoneNumber;
            newEvent.SMSText = smsText;

            SmsMessage msg = new SmsMessage();
            msg.Body = smsText;
            msg.To.Add(new Recipient(phoneNumber));

            if (live && !sendSms(msg, newEvent))
            {
                newEvent.eventType = HOHEvent.HOHEventType.SendFailedEventType;
            }
            dataManager.addEvents(new List<HOHEvent>(new HOHEvent[] { newEvent }), live);
        }
Esempio n. 9
0
        internal void sendSmsHintForTeamAndPuzzle(HOHTeam team, HOHPuzzle puzzle, string phoneNumber, bool live)
        {
            if (puzzle == null) return;

            if (puzzle.hint.Equals("")) return;

            string smsText = String.Format("Napoveda pro {0}: {1}", puzzle.name, puzzle.hint);

            HOHEvent newEvent = new HOHEvent(HOHEvent.HOHEventType.HintReplyEventType);
            newEvent.team = team;
            newEvent.puzzle = puzzle;
            newEvent.phoneNumber = phoneNumber;
            newEvent.SMSText = smsText;

            SmsMessage msg = new SmsMessage();
            msg.Body = smsText;
            msg.To.Add(new Recipient(phoneNumber));

            if (live && !sendSms(msg, newEvent))
            {
                newEvent.eventType = HOHEvent.HOHEventType.SendFailedEventType;
            }
            dataManager.addEvents(new List<HOHEvent>(new HOHEvent[] { newEvent }), live);
        }
Esempio n. 10
0
 private void puzzlesComboBox_SelectedIndexChanged_1(object sender, EventArgs e)
 {
     if (this.puzzlesComboBox.SelectedIndex >= 0 && this.puzzlesComboBox.SelectedIndex < this.puzzlesComboBoxBinding.Count)
         this.selectedPuzzle = this.puzzlesComboBoxBinding[this.puzzlesComboBox.SelectedIndex];
     else
         this.selectedPuzzle = null;
     this.refreshPuzzlesViews(this.dataManager);
 }