public void Registering_wins_after_game_over_does_not_change_score()
 {
     var sut = new Referee("A", "B", new[] {3, 2}); // 40:30
     var score = sut.RegisterWinFor(Referee.Players.Player1); // A wins the game
     score = sut.RegisterWinFor(Referee.Players.Player2);
     Assert.AreEqual("Game over", score);
 }
Пример #2
0
        /// <summary>
        /// check whether the position is forbidden
        /// </summary>
        /// <returns>if it is forbidden ,true;otherwise ,false
        /// </returns>
        private bool IsFobidden(ref IChessBoard chessBoard,Position point,PieceTypeEnum pieceType)
        {
            Referee platformCheck = new Referee();
            PlayStepResultEnum stepResult=platformCheck.Check(chessBoard, new ChessBoardPoint(point.Row, point.Col), PieceTypeEnum.Black);
            //it seems the platform does not check four-three-three

                if (stepResult == PlayStepResultEnum.Four_Four ||
                   stepResult == PlayStepResultEnum.Three_Three ||
                   stepResult == PlayStepResultEnum.Overline)
                {
                    if (pieceType == PieceTypeEnum.Black)
                    {
                        return true;
                    }
                    else
                    {
                        stepResult = platformCheck.Check(chessBoard, new ChessBoardPoint(point.Row, point.Col), PieceTypeEnum.White);
                        if (stepResult == PlayStepResultEnum.Four_Four ||
                            stepResult == PlayStepResultEnum.Three_Three||
                            stepResult==PlayStepResultEnum.Win)
                        {
                            return false;
                        }
                    }
                }

            return false;
        }
Пример #3
0
 public void Reflects_score_returned_by_last_RegisterWinFor_call()
 {
     var sut = new Referee("", "");
     Assert.AreEqual("Love:Love", sut.CurrentScore);
     sut.RegisterWinFor(Referee.Players.Player1);
     Assert.AreEqual("15:Love", sut.CurrentScore);
 }
Пример #4
0
        // Public Methods (1)
        /// <summary>
        /// Waits until the machine player figures what move to play
        /// </summary>
        /// <returns>Machine player's move</returns>
        public override Move WaitForMove()
        {
            Move theMove = null;
            Referee theReferee = new Referee();
            int maxGrade = -100;

            for (int row = 0; row < GameBoard.Rows; row++)
            {
                for (int column = 0; column < GameBoard.Columns; column++)
                {
                    if (this.GameBoard[row, column] == PlayerToken.Empty)
                    {
                        // Get a board clone
                        GameBoard hypoBoard = this.GameBoard.Clone();

                        // Make the hypothetical move on the cloned board
                        Move hypoMove = new Move(row, column, this.PlayerToken);
                        theReferee.ApplyMove(hypoBoard, hypoMove);

                        // Grade the new board
                        int grade = this.Grade(hypoBoard);

                        // Keep the move as a candid if it's got good grade
                        if (grade > maxGrade)
                        {
                            maxGrade = grade;
                            theMove = hypoMove;
                        }
                    }
                }
            }

            return theMove;
        }
        public void Entering_deuce_state()
        {
            var sut = new Referee("", "", new[] { 3, 2 }); // 40:30

            var score = sut.RegisterWinFor(Referee.Players.Player2);

            Assert.AreEqual("Deuce", score);
        }
        public void Second_win_same_player()
        {
            var sut = new Referee("", "");

            sut.RegisterWinFor(Referee.Players.Player1);
            var score = sut.RegisterWinFor(Referee.Players.Player1);

            Assert.AreEqual("30:Love", score);
        }
        public void Players_winning_alternately()
        {
            var sut = new Referee("", "");

            sut.RegisterWinFor(Referee.Players.Player1);
            sut.RegisterWinFor(Referee.Players.Player2);
            var score = sut.RegisterWinFor(Referee.Players.Player1);

            Assert.AreEqual("30:15", score);
        }
        public void Winning_a_game_without_deuce()
        {
            var sut = new Referee("", "");

            sut.RegisterWinFor(Referee.Players.Player1);
            sut.RegisterWinFor(Referee.Players.Player1);
            sut.RegisterWinFor(Referee.Players.Player1);
            var score = sut.RegisterWinFor(Referee.Players.Player1);

            Assert.AreEqual("Game over", score);
        }
Пример #9
0
    /// <summary>
    ///     Retrieve the necessary object and script references
    /// </summary>
    void Start()
    {
        GameObject gameController = GameObject.FindGameObjectWithTag("GameController");
        gameTimer = gameController.GetComponent<GameTimer>();
        scoreKeeper = gameController.GetComponent<ScoreKeeper>();
        referee = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        breakTimer = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();

        timer = gameObject.GetComponent<Timer>();
        timer.SetLengthOfTimer(announcementPauseLength);
    }
Пример #10
0
    /// <summary>
    /// Initialize all variables needed for this script to run.
    /// </summary>
    void Start () 
    {
        timer = GetComponent<Timer>();
        timer.SetLengthOfTimer(halfLength + 1);
        timer.Pause();
        referee = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        GameObject gameController = GameObject.FindGameObjectWithTag("GameController");
        scoreKeeper = gameController.GetComponent<ScoreKeeper>();
        ballReset = gameController.GetComponent<BallReset>();
        breakTimer = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();
	}
Пример #11
0
 public void Non_deuce_game()
 {
     var sut = new Referee("A", "B");
     sut.RegisterWinFor(Referee.Players.Player2);
     sut.RegisterWinFor(Referee.Players.Player2);
     sut.RegisterWinFor(Referee.Players.Player1);
     Assert.AreEqual("15:30", sut.CurrentScore);
     sut.RegisterWinFor(Referee.Players.Player1);
     sut.RegisterWinFor(Referee.Players.Player1);
     Assert.AreEqual("Game over", sut.RegisterWinFor(Referee.Players.Player1));
     Assert.AreEqual("A", sut.Winner);
 }
Пример #12
0
    /// <summary>
    /// Gets the objects and initializes the variables to their proper values.
    /// </summary>
    void Start ()
    {
        if (isServer)
        {
            BlueTeamScore = 0;
            RedTeamScore = 0;
        }
        GameObject gameController = GameObject.FindGameObjectWithTag("GameController");

        GT = gameController.GetComponent<GameTimer>();
        BR = gameController.GetComponent<BallReset>();
        Ref = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        BT = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();
	}
Пример #13
0
        public void GetGameOutcomeTestWin()
        {
            //initialize
            Referee target = new Referee();
            RpsEnum player = RpsEnum.Rock;
            RpsEnum ai = RpsEnum.Scissors;
            OutcomeEnum expected = OutcomeEnum.WinWithRock;
            OutcomeEnum actual;

            //setup
            actual = target.GetGameOutcome(player, ai);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #14
0
        public static List<Referee> GetReferees(string refereeFile, int refereeLimit)
        {
            var referees = new List<Referee>();
            var rnd = new Random();
            foreach (var line in File.ReadLines(refereeFile).Take(refereeLimit))
            {
                var splitLine = line.Split('|');

                // A bit complicated just to randomize the gender of the referees, but hey, they can't all be males. http://stackoverflow.com/questions/3132126/how-do-i-select-a-random-value-from-an-enumeration
                var gender = (Gender) Enum.GetValues(typeof(Gender)).GetValue(rnd.Next(2));
                var referee = new Referee(int.Parse(splitLine[0]), splitLine[1], splitLine[2], splitLine[3], DateTime.Parse(splitLine[4]), splitLine[5], splitLine[6], gender, DateTime.Parse(splitLine[7]), DateTime.Parse(splitLine[8]));
                referees.Add(referee);
            }

            return referees;
        }
Пример #15
0
    /// <summary>
    /// Initializes all of the objects and variables needed for this script.
    /// </summary>
    void Start () 
    {
        GameObject GameController = GameObject.FindGameObjectWithTag("GameController");
        REF = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
        BR = GameController.GetComponent<BallReset>();
        GT = GameController.GetComponent<GameTimer>();
        BT = GameObject.Find("BreakTimer").GetComponent<BreakTimer>();
        
        ballPossession = ball.GetComponent<Possession>();
        ballLocation = ball.GetComponent<ListObjectLocation>();
        timer = gameObject.AddComponent<Timer>();
        timer.SetLengthOfTimer(TimerFoulTime);
        timer.Resume();
        DeadBallTimer = gameObject.AddComponent<Timer>();
        DeadBallTimer.SetLengthOfTimer(DeadBallTime);
        DeadBallTimer.Pause();
	}
Пример #16
0
 public void Deuce_game()
 {
     var sut = new Referee("A", "B");
     sut.RegisterWinFor(Referee.Players.Player1);
     sut.RegisterWinFor(Referee.Players.Player2);
     sut.RegisterWinFor(Referee.Players.Player1);
     sut.RegisterWinFor(Referee.Players.Player1);
     sut.RegisterWinFor(Referee.Players.Player2);
     sut.RegisterWinFor(Referee.Players.Player2);
     Assert.AreEqual("Deuce", sut.CurrentScore);
     sut.RegisterWinFor(Referee.Players.Player1);
     sut.RegisterWinFor(Referee.Players.Player2);
     sut.RegisterWinFor(Referee.Players.Player2);
     Assert.AreEqual("Advantage B", sut.CurrentScore);
     sut.RegisterWinFor(Referee.Players.Player2);
     Assert.AreEqual("Game over", sut.CurrentScore);
     Assert.AreEqual("B", sut.Winner);
 }
Пример #17
0
        public override bool ProceedProtectiveSuit(Player player, Player rival, Card myCard, string move, List <string> wholemoves)
        {
            bool psused = SomeoneHasDefend();

            bool play = rival.DoIHaveProtectiveSuit();

            if (play)
            {
                if (rival.AI == ArtificialIntelligence.AICategory.Human)
                {
                    string warning = String.Format(
                        "{0} is trying to play a {1} against {2}. Do you want to protect?",
                        player.Nickname, myCard.ToString(), GetMyCardAffectedFromMove(rival, myCard, move));

                    play = (MessageBox.Show(warning, "Protective Suit chance",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                            MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes);

                    if (play)
                    {
                        int index = -1;
                        for (int i = 0; i < rival.Hand.Count; i++)
                        {
                            if (rival.Hand[i].Face == Card.CardFace.ProtectiveSuit)
                            {
                                index = i;
                            }
                        }
                        DiscardFromHand(rival, index);
                        rival.PlayedProtectiveSuit = true;
                    }
                }
                else
                {
                    play = rival.Computer.DefendFromCard(player, myCard, move);
                }

                if (play)
                {
                    WriteToLog(rival.Nickname + " has protected with a Protective Suit.", true);



                    if (wholemoves == null)
                    {
                        // Playable cards that doesn't require play a move.
                    }
                    else
                    {
                        if (!psused)
                        {
                            wholemoves = Referee.GetListMovements(player, myCard, true);
                        }
                        wholemoves = Referee.RemoveMovesPlayer(wholemoves, rival.ID, myCard, player);

                        if (player.AI == ArtificialIntelligence.AICategory.Human)
                        {
                            if (wholemoves.Count == 0)
                            {
                                return(true);
                            }
                            return(PlayGameCardByUser(player, -1, wholemoves, myCard));
                        }
                        else
                        {
                            move = player.Computer.ChooseBestOptionProtectiveSuit(wholemoves);
                            if (move != null)
                            {
                                PlayCardByMove(player, myCard, move, wholemoves, false);
                            }
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }
Пример #18
0
 public async Task <Referee> Update(Referee model)
 {
     return(await this.rm.Referee.Update(model));
 }
Пример #19
0
        public static bool SetMatchRestrictions()
        {
            if (!isIronMan)
            {
                return(false);
            }
            else
            {
                //Determine if this is a draw
                MatchMain main = MatchMain.inst;

                //If a victory condition is met
                if (!main.isTimeUp)
                {
                    //Signal that the current round has ended
                    Referee matchRef = RefereeMan.inst.GetRefereeObj();
                    matchRef.PlDir = PlDirEnum.Left;
                    matchRef.ReqRefereeAnm(BasicSkillEnum.Refe_Stand_MatchEnd_Front_Left);
                    Announcer.inst.PlayGong_Eliminated();

                    int loser = 0;
                    for (int i = 0; i < 8; i++)
                    {
                        Player plObj = PlayerMan.inst.GetPlObj(i);
                        if (!plObj)
                        {
                            continue;
                        }
                        if (plObj.isLose)
                        {
                            loser = i;
                        }
                        if (plObj.isKO)
                        {
                            plObj.isKO = false;
                        }
                    }

                    //Record the last win and display the current score
                    if (loser <= 3)
                    {
                        wins[1]++;
                    }
                    else
                    {
                        wins[0]++;
                    }

                    //Prepare the next round
                    WaitForNextRound();
                    main.isMatchEnd = false;
                    main.isRoundEnd = true;
                    currMatchTime   = new MatchTime
                    {
                        min = main.matchTime.min,
                        sec = main.matchTime.sec
                    };
                    main.isTimeCounting = false;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #20
0
 public Notification(Game game, Referee referee)
 {
     this.Game    = game;
     this.Referee = referee;
 }
Пример #21
0
        public Referee GetRefereeById(int refereeId)
        {
            Referee r = refereeList.Select(x => x).Where(x => x.Id == refereeId).FirstOrDefault();

            return(r);
        }
Пример #22
0
 public void Game_still_on()
 {
     var sut = new Referee("A", "B");
     Assert.AreEqual("", sut.Winner);
 }
Пример #23
0
 public void AddReferee(Referee referee)
 {
     Referee = referee;
 }
Пример #24
0
 public ApplyToBeMasterHandler(IServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider;
     _referee         = serviceProvider.GetService <Referee>();
 }
Пример #25
0
 public void AddRefereeTest()
 {
     var referee = new Referee();
 }
Пример #26
0
 void Start()
 {
     cs_referee = GS_Referee.GetComponent <Referee>();
 }
Пример #27
0
 // Use this for initialization
 void Start()
 {
     Scripts = GameObject.Find("Scripts");
     myRef   = Scripts.GetComponent <Referee> ();
 }
Пример #28
0
        public bool PlayGameCardByUser(Player player, int index, List <string> moves = null, Card myCard = null)
        {
            if (myCard == null)
            {
                myCard = player.Hand[index];
            }

            if (moves == null)
            {
                moves = Referee.GetListMovements(player, myCard);
            }

            switch (moves.Count)
            {
            case 0: return(false);

            case 1:
                PlayCardByMove(player, myCard, moves[0], moves);
                return(true);

            default:
                string choosen = null;
                switch (myCard.Face)
                {
                case Card.CardFace.Transplant:
                    choosen = reader.RequestMovementChoosenTransplant(moves, this);
                    break;

                case Card.CardFace.Spreading:
                    List <List <string> > wholeMoves = Scheduler.GetListOfListsSpreadingMoves(Referee.GetListMovements(player, myCard));
                    if (wholeMoves.Count == 0)
                    {
                        return(false);
                    }
                    if (wholeMoves.Count > 0)
                    {
                        List <string> choosenlist = new List <string>();
                        foreach (var move in wholeMoves)
                        {
                            string input = ProcessSpreadingItem(move);
                            if (input == null)
                            {
                                return(false);
                            }
                            else
                            {
                                choosenlist.Add(input);
                            }
                        }
                        PlayGameCardSpreading(player, myCard, Scheduler.GetMoveByMultiple(choosenlist), moves);
                        return(true);
                    }
                    break;

                case Card.CardFace.MedicalError:
                case Card.CardFace.SecondOpinion:
                    choosen = reader.RequestMovementChoosenMedicalError(player, moves, this);
                    break;

                default:
                    choosen = reader.RequestMovementChoosen(player, moves);
                    break;
                }

                if (choosen == null)
                {
                    return(false);
                }

                PlayCardByMove(player, myCard, choosen, moves);
                return(true);
            }
        }
Пример #29
0
 public void Delete(int ID)
 {
     Referee selectedlst = _Referee.Remove(_Referee.Find(ID));
 }
Пример #30
0
    public string MakeMove(Referee referee, bool getMoveAsString)
    {
        string result = "";

        var items            = referee.Board.Players[referee.PlayerNumber].Cards.Where(c => c.Type != CardType.Creature).ToList();
        var playerCardsCount = referee.Board.PlayersBoards[referee.PlayerNumber].Count;

        foreach (var item in items)
        {
            var creatureId = -2;
            if (item.Type == CardType.ItemGreen && playerCardsCount > 0)
            {
                var creature = _random.Next(-playerCardsCount - 1, playerCardsCount);

                if (creature > -1)
                {
                    creatureId = referee.Board.PlayersBoards[referee.PlayerNumber][creature].InstanceId;
                }
            }
            else if (item.Type == CardType.ItemRed)
            {
                var enemyCreaturesCount = referee.Board.PlayersBoards[referee.DeffenderNumber].Count;
                if (enemyCreaturesCount > 0)
                {
                    var creature = _random.Next(-enemyCreaturesCount - 1, enemyCreaturesCount);

                    if (creature > -1)
                    {
                        creatureId = referee.Board.PlayersBoards[referee.DeffenderNumber][creature].InstanceId;
                    }
                }
            }
            else if (item.Type == CardType.ItemBlue)
            {
                var enemyCreaturesCount = referee.Board.PlayersBoards[referee.DeffenderNumber].Count;
                var creature            = _random.Next(-enemyCreaturesCount - 2, enemyCreaturesCount);

                if (creature > -2)
                {
                    creatureId = creature != -1 ? referee.Board.PlayersBoards[referee.DeffenderNumber][creature].InstanceId : creature;
                }
            }

            if (creatureId != -2)
            {
                referee.Use(item.InstanceId, creatureId);

                if (getMoveAsString)
                {
                    result += $"USE {item.InstanceId} {creatureId}; ";
                }
            }
        }


        var cardIds = referee.Board.PlayersBoards[referee.PlayerNumber].Where(c => c.Type == CardType.Creature).Select(c => new { c.InstanceId, PlayType = "S" }).ToList();

        if (referee.Board.PlayersBoards[referee.PlayerNumber].Count < 6)
        {
            cardIds.AddRange(referee.Board.Players[referee.PlayerNumber].Cards.Where(c => c.Type == CardType.Creature && c.Abilities.Contains("C")).Select(c => new { c.InstanceId, PlayType = "C" }));
        }

        var count = cardIds.Count;

        for (int i = 0; i < count; i++)
        {
            var enemyBoard      = referee.Board.PlayersBoards[referee.DeffenderNumber];
            var hasGuards       = enemyBoard.Any(c => c.Abilities.Contains("G"));
            var enemyCards      = hasGuards ? enemyBoard.Where(c => c.Abilities.Contains("G")) : enemyBoard;
            var enemyCardsCount = enemyCards.Count();

            var deffender = _random.Next(-2, enemyCardsCount);
            if (deffender == -1 && hasGuards)
            {
                deffender = 0;
            }
            var attacker     = _random.Next(cardIds.Count);
            var attackerItem = cardIds[attacker];
            cardIds.RemoveAt(attacker);

            if (deffender != -2)
            {
                if (deffender != -1)
                {
                    deffender = enemyCards.ElementAt(deffender).InstanceId;
                }

                if (attackerItem.PlayType == "C")
                {
                    var card = referee.Board.Players[referee.PlayerNumber].Cards.FirstOrDefault(c => c.InstanceId == attackerItem.InstanceId);

                    if (card.Cost > referee.Board.Players[referee.PlayerNumber].Mana)
                    {
                        referee.Summon(attackerItem.InstanceId);
                        referee.Attack(attackerItem.InstanceId, deffender);

                        if (getMoveAsString)
                        {
                            result += $"SUMMON {attackerItem.InstanceId}; ";
                            result += $"ATTACK {attackerItem.InstanceId} {deffender}; ";
                        }
                    }
                }
                else
                {
                    referee.Attack(attackerItem.InstanceId, deffender);

                    if (getMoveAsString)
                    {
                        result += $"ATTACK {attackerItem.InstanceId} {deffender}; ";
                    }
                }
            }
        }

        var cards = referee.Board.Players[referee.PlayerNumber].Cards.Select(c => new { c.InstanceId, c.Cost }).ToList();

        if (referee.Board.PlayersBoards[referee.PlayerNumber].Count < 6)
        {
            foreach (var item in cards)
            {
                if (item.Cost > referee.Board.Players[referee.PlayerNumber].Mana)
                {
                    continue;
                }

                var summon = _random.Next(1) == 0;

                if (summon)
                {
                    referee.Summon(item.InstanceId);
                }

                if (getMoveAsString)
                {
                    result += $"SUMMON {item.InstanceId}; ";
                }
            }
        }

        referee.EndMove();

        return(result);
    }
Пример #31
0
 // Use this for initialization
 void Start()
 {
     Scripts = GameObject.Find ("Scripts");
     myRef = Scripts.GetComponent<Referee> ();
 }
        public void RefereeAttendToMatchShouldNotReturnNull()
        {
            var options = new DbContextOptionsBuilder <FooteoDbContext>()
                          .UseInMemoryDatabase(databaseName: "AttendToMatch_Referees_DB")
                          .Options;

            var dbContext    = new FooteoDbContext(options);
            var townsService = new TownsService(dbContext);

            var town = townsService.CreateTown("Burgas");

            var user = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Referee",
                UserName     = $"footeoReferee",
                Town         = town,
                PasswordHash = "123123"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var userHT = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(userHT);
            dbContext.SaveChanges();

            var userAT = new FooteoUser
            {
                Age          = new Random().Next(20, 30),
                Email        = $"*****@*****.**",
                FirstName    = "Footeo",
                LastName     = "Player",
                UserName     = $"footeoPlayer2",
                Town         = town,
                PasswordHash = "123123",
                Player       = new Player
                {
                    FullName = "Footeo Player"
                }
            };

            dbContext.Users.Add(userAT);
            dbContext.SaveChanges();

            var mockUserStore = new Mock <IUserStore <FooteoUser> >();
            var userManager   = new Mock <UserManager <FooteoUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            userManager.Setup(u => u.RemoveFromRoleAsync(userHT, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userHT, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userHT, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            userManager.Setup(u => u.RemoveFromRoleAsync(userAT, "Player")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userAT, "PlayerInTeam")).Returns(Task.FromResult(IdentityResult.Success));
            userManager.Setup(u => u.AddToRoleAsync(userAT, "Captain")).Returns(Task.FromResult(IdentityResult.Success));

            var fieldsService      = new FieldsService(dbContext, townsService);
            var leaguesService     = new LeaguesService(dbContext, townsService);
            var teamsService       = new TeamsService(dbContext, townsService, leaguesService, userManager.Object, null);
            var teamLeaguesService = new TeamLeaguesService(dbContext, teamsService, leaguesService);
            var fixturesService    = new FixturesService(dbContext, leaguesService);
            var matchesService     = new MatchesService(dbContext, fixturesService, teamsService);
            var refereesService    = new RefereesService(dbContext, matchesService, teamLeaguesService);

            var referee = new Referee
            {
                FullName = $"Footeo Referee"
            };

            refereesService.CreateReferee(user, referee);

            townsService.CreateTown("Sofia");
            leaguesService.CreateLeague("League", "Desc", DateTime.UtcNow, DateTime.UtcNow.AddMonths(3), "Sofia");

            teamsService.CreateTeam("Home Team", "HT", userHT.UserName);
            teamsService.CreateTeam("Away Team", "AT", userAT.UserName);

            var league = dbContext.Leagues.FirstOrDefault(n => n.Name == "League");

            teamLeaguesService.JoinLeague(userHT.UserName, league.Id);
            teamLeaguesService.JoinLeague(userAT.UserName, league.Id);

            fixturesService.CreateFixture("Matchday", DateTime.UtcNow.AddDays(7), league.Id);
            var fixture = dbContext.Fixtures.FirstOrDefault(n => n.Name == "Matchday");

            fieldsService.CreateField("Field", "Address", true, "Sofia");
            var field = dbContext.Fields.FirstOrDefault(n => n.Name == "Field");

            matchesService.CreateMatch(userHT.Player.Team.Id, userAT.Player.Team.Id, field.Id, fixture.Id);
            var match = dbContext.Matches.FirstOrDefault();

            refereesService.AttendAMatch(user.UserName, match.Id);

            Assert.NotNull(match.Referee);
        }
Пример #33
0
        public ChessBoardPoint GetNextStep(IChessBoard chessBoard, PieceTypeEnum pieceType, int stepIndex, PlayStep? prevStep)
        {
            int[] tupleScoreTable = new int[11] { 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            //initialize tuple score table
            if (stepIndex % 2 == 0)//even step is first hand,i.e. the black side
            {
                if (stepIndex == 0)
                {
                    return ChessBoardPoint.TENGEN;
                }
                else if(stepIndex==2)
                {
                    Position[][] classicalOpen = new Position[8][];
                    //0:white is on left side of Tengen
                    classicalOpen[0]=new Position[21]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //1:white is on up side of Tengen
                    classicalOpen[1]=new Position[21]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //2:white is on right side of Tengen
                    classicalOpen[2]=new Position[21]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //3:white is on bottom side of Tengen
                    classicalOpen[3]=new Position[21]{
                        new Position(8,8),new Position(9,7),new Position(7,8),new Position(7,9),
                        new Position(8,9),new Position(6,9),new Position(5,8),new Position(6,8),
                        new Position(6,7),new Position(5,7),new Position(9,9),new Position(5,5),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //4:white is on topleft corner of Tengen
                    classicalOpen[4]=new Position[25]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //5:white is on topright corner of Tengen
                    classicalOpen[5]=new Position[25]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //6:white is on bottomright corner of Tengen
                    classicalOpen[6]=new Position[25]{
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};
                    //7:white is on bottomleft corner of Tengen
                    classicalOpen[7] = new Position[25]{
                        new Position(6,6),new Position(7,5),new Position(7,6),new Position(6,5),
                        new Position(8,5),new Position(6,8),new Position(9,5),new Position(7,9),
                        new Position(5,5),new Position(5,6),new Position(7,8),new Position(5,8),
                        new Position(5,9),new Position(8,5),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position(),new Position(),new Position(),new Position(),
                        new Position()};

                    Position whiteFirst = new Position(14-prevStep.Value.Location.RowIndex, prevStep.Value.Location.ColumnIndex);
                    switch ()
                    {
                    case :
                        break;
                    }
                }
                tupleScoreTable[1] = 35;
                tupleScoreTable[2] = 800;
                tupleScoreTable[3] = 15000;
                tupleScoreTable[4] = 800000;
                tupleScoreTable[5] = 15;
                tupleScoreTable[6] = 400;
                tupleScoreTable[7] = 1800;
                tupleScoreTable[8] = 100000;
            }
            else//odd step is back hand,i.e. the white side
            {
                tupleScoreTable[1] = 15;
                tupleScoreTable[2] = 400;
                tupleScoreTable[3] = 1800;
                tupleScoreTable[4] = 100000;
                tupleScoreTable[5] = 35;
                tupleScoreTable[6] = 800;
                tupleScoreTable[7] = 15000;
                tupleScoreTable[8] = 800000;
            }

            //extended board,with virtual points
            ExtendedPointStateEnum[,] exPointStates = new ExtendedPointStateEnum[23, 23];
            for (int row = 0; row < 23; row++)
            {
                for (int col = 0; col < 23; col++)
                {
                    if (row < 4 || row > 18 || col < 4 || col > 18)
                    {
                        exPointStates[row, col] = ExtendedPointStateEnum.Virtual;
                    }
                    else
                    {
                        exPointStates[row, col] = (ExtendedPointStateEnum)chessBoard.GetPointState(14 - (row - 4), col - 4);
                    }
                }
            }

            int[,] scoreTable = new int[15, 15];

            /// <summary>calculate type of every tuple</summary>
            /// <description>In order to give a clear train of thought,
            /// I used an intuitionistic method to do this work.
            /// But this results in not efficient.
            /// Every tuple is calculated for twice.
            /// But it's easy to modify it:two ends of a tuple own the same tuple
            /// I'll modify it in next version ,where efficiency becomes bottleneck.
            /// </description>
            //every point indexs 8 tuples around it
            TupleType[, ,] tupleTable = new TupleType[15, 15, 8];
            for (int row = 4; row < 19; row++)
            {
                for (int col = 4; col < 19; col++)
                {
                    int[] white = new int[8];//white points in a tuple
                    int[] black = new int[8];//black points in a tuple
                    #region ---check tuples of every direction
                    //left ,index 0
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 0] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[0]++;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[0]++;
                        }
                    }
                    //top left,index 1
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 1] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[1]++;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[1]++;
                        }
                    }
                    //up ,index 2
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 2] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[2]++;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.White)
                        {
                            white[2]++;
                        }
                    }
                    //top right,index 3
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 3] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[3]++;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[3]++;
                        }
                    }
                    //right,index 4
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 4] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[4]++;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[4]++;
                        }
                    }
                    //bottom right,index 5
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 5] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[5]++;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[5]++;
                        }
                    }
                    //bottom,index 6
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 6] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[6]++;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.White)
                        {
                            white[6]++;
                        }
                    }
                    //bottom left,index 7
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 7] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[7]++;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[7]++;
                        }
                    }
                    #endregion //check tuples of every direction

                    //decide tuple type
                    for (int i = 0; i < 8; i++)
                    {
                        //already assigned
                        if (tupleTable[row - 4, col - 4, i] == TupleType.Virtual)
                        {
                            continue;
                        }
                        if (white[i] > 0 && black[i] > 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Polluted;
                        }
                        else if (white[i] == 0 && black[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Blank;
                        }
                        else if (white[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)black[i];
                        }
                        else
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)(white[i] + 4);
                        }
                    }
                }
            }
            #region ---scoreTable calculate
            //calculate score table . using symmetry
            //top left corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];//bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]];//bottom right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];//right
                    }
                }
            }
            //top right corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];//bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]];//bottom left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];//left
                    }
                }
            }
            //bottom left corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];//top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]];//top right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];//right
                    }
                }
            }
            //bottom right corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];//top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]];//top left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];//left
                    }
                }
            }
            #endregion //scoreTable

            //select best position
            List<Position> bestList = new List<Position>();

            //select first valid point
            Position first = new Position(0, 0);
            //all the point is forbidden.connot happen
            //while (IsFobidden(first))
            //{
            //    while (IsFobidden(first))
            //    {
            //        if (first.Col<14)
            //        {
            //            first.Col++;
            //        }
            //        else
            //        {
            //            break;
            //        }
            //    }
            //    if (first.Row<14)
            //    {
            //        first.Row++;
            //    }
            //    else
            //    {
            //        break;
            //    }
            //}
            while (IsFobidden(ref chessBoard, first, pieceType))
            {
                if (first.Col < 14)
                {
                    first.Col++;
                }
                else if (first.Row < 14)
                {
                    first.Row++;
                    first.Col = 0;
                }
                else
                {
                    return new ChessBoardPoint(-1, -1);
                }
            }
            bestList.Add(first);

            Referee checkWin = new Referee();
            //select best points
            for (int row = 0; row < 15; row++)
            {
                for (int col = 0; col < 15; col++)
                {
                    if (scoreTable[row, col] > scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Clear();
                            bestList.Add(best);
                        }

                    }
                    else if (scoreTable[row, col] == scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Add(best);
                        }
                    }
                }
            }
            //there is no best .connot happen
            if (bestList.Count == 0)
            {
                return new ChessBoardPoint(-1, -1);
            }
            Position ret = bestList[(new Random()).Next(bestList.Count)];
            return new ChessBoardPoint(14 - ret.Row, ret.Col);
        }
Пример #34
0
 public RefereeController(RefereeWindow refereeWindow, Referee myRefereeAccount)
     : this(NHibernateHelper.Instance.OpenSession())
 {
     _refereeWindow    = refereeWindow;
     _myRefereeAccount = myRefereeAccount;
 }
Пример #35
0
        public void HandleOutcomeTestWinNoHistory()
        {
            //initialize
            Referee target = new Referee() { IsTest = true };
            OutcomeEnum outcomeOfRound = OutcomeEnum.WinWithRock;
            List<OutcomeEnum> gameOutcomes = null;
            string expectedGameHistoryUpdate = "R";
            string actualGameHistoryUpdate;
            string expected = System.Environment.NewLine + "You " + Referee_Accessor.won;
            string actual;

            //setup
            actual = target.HandleOutcome(outcomeOfRound, ref gameOutcomes, out actualGameHistoryUpdate);

            //assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expectedGameHistoryUpdate, actualGameHistoryUpdate);
        }
Пример #36
0
        public ChessBoardPoint GetNextStep(IChessBoard chessBoard, PieceTypeEnum pieceType, int stepIndex, PlayStep?prevStep)
        {
            int[] tupleScoreTable = new int[11] {
                7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            //initialize tuple score table
            if (stepIndex % 2 == 0)//even step is first hand,i.e. the black side
            {
                if (stepIndex == 0)
                {
                    return(ChessBoardPoint.TENGEN);
                }
                else if (stepIndex == 2)
                {
                    Position[][] classicalOpen = new Position[8][];
                    //0:white is on left side of Tengen
                    classicalOpen[0] = new Position[21] {
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //1:white is on up side of Tengen
                    classicalOpen[1] = new Position[21] {
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //2:white is on right side of Tengen
                    classicalOpen[2] = new Position[21] {
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //3:white is on bottom side of Tengen
                    classicalOpen[3] = new Position[21] {
                        new Position(8, 8), new Position(9, 7), new Position(7, 8), new Position(7, 9),
                        new Position(8, 9), new Position(6, 9), new Position(5, 8), new Position(6, 8),
                        new Position(6, 7), new Position(5, 7), new Position(9, 9), new Position(5, 5),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //4:white is on topleft corner of Tengen
                    classicalOpen[4] = new Position[25] {
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //5:white is on topright corner of Tengen
                    classicalOpen[5] = new Position[25] {
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //6:white is on bottomright corner of Tengen
                    classicalOpen[6] = new Position[25] {
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };
                    //7:white is on bottomleft corner of Tengen
                    classicalOpen[7] = new Position[25] {
                        new Position(6, 6), new Position(7, 5), new Position(7, 6), new Position(6, 5),
                        new Position(8, 5), new Position(6, 8), new Position(9, 5), new Position(7, 9),
                        new Position(5, 5), new Position(5, 6), new Position(7, 8), new Position(5, 8),
                        new Position(5, 9), new Position(8, 5), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position(), new Position(), new Position(), new Position(),
                        new Position()
                    };

                    Position whiteFirst = new Position(14 - prevStep.Value.Location.RowIndex, prevStep.Value.Location.ColumnIndex);
                    switch ()
                    {
                    case:
                        break;
                    }
                }
                tupleScoreTable[1] = 35;
                tupleScoreTable[2] = 800;
                tupleScoreTable[3] = 15000;
                tupleScoreTable[4] = 800000;
                tupleScoreTable[5] = 15;
                tupleScoreTable[6] = 400;
                tupleScoreTable[7] = 1800;
                tupleScoreTable[8] = 100000;
            }
            else//odd step is back hand,i.e. the white side
            {
                tupleScoreTable[1] = 15;
                tupleScoreTable[2] = 400;
                tupleScoreTable[3] = 1800;
                tupleScoreTable[4] = 100000;
                tupleScoreTable[5] = 35;
                tupleScoreTable[6] = 800;
                tupleScoreTable[7] = 15000;
                tupleScoreTable[8] = 800000;
            }

            //extended board,with virtual points
            ExtendedPointStateEnum[,] exPointStates = new ExtendedPointStateEnum[23, 23];
            for (int row = 0; row < 23; row++)
            {
                for (int col = 0; col < 23; col++)
                {
                    if (row < 4 || row > 18 || col < 4 || col > 18)
                    {
                        exPointStates[row, col] = ExtendedPointStateEnum.Virtual;
                    }
                    else
                    {
                        exPointStates[row, col] = (ExtendedPointStateEnum)chessBoard.GetPointState(14 - (row - 4), col - 4);
                    }
                }
            }

            int[,] scoreTable = new int[15, 15];

            /// <summary>calculate type of every tuple</summary>
            /// <description>In order to give a clear train of thought,
            /// I used an intuitionistic method to do this work.
            /// But this results in not efficient.
            /// Every tuple is calculated for twice.
            /// But it's easy to modify it:two ends of a tuple own the same tuple
            /// I'll modify it in next version ,where efficiency becomes bottleneck.
            /// </description>
            //every point indexs 8 tuples around it
            TupleType[, ,] tupleTable = new TupleType[15, 15, 8];
            for (int row = 4; row < 19; row++)
            {
                for (int col = 4; col < 19; col++)
                {
                    int[] white = new int[8]; //white points in a tuple
                    int[] black = new int[8]; //black points in a tuple
                    #region ---check tuples of every direction
                    //left ,index 0
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 0] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[0]++;
                        }
                        else if (exPointStates[row, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[0]++;
                        }
                    }
                    //top left,index 1
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 1] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[1]++;
                        }
                        else if (exPointStates[row - i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[1]++;
                        }
                    }
                    //up ,index 2
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 2] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[2]++;
                        }
                        else if (exPointStates[row - i, col] == ExtendedPointStateEnum.White)
                        {
                            white[2]++;
                        }
                    }
                    //top right,index 3
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 3] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[3]++;
                        }
                        else if (exPointStates[row - i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[3]++;
                        }
                    }
                    //right,index 4
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 4] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[4]++;
                        }
                        else if (exPointStates[row, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[4]++;
                        }
                    }
                    //bottom right,index 5
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 5] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.Black)
                        {
                            black[5]++;
                        }
                        else if (exPointStates[row + i, col + i] == ExtendedPointStateEnum.White)
                        {
                            white[5]++;
                        }
                    }
                    //bottom,index 6
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 6] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.Black)
                        {
                            black[6]++;
                        }
                        else if (exPointStates[row + i, col] == ExtendedPointStateEnum.White)
                        {
                            white[6]++;
                        }
                    }
                    //bottom left,index 7
                    for (int i = 0; i < 5; i++)
                    {
                        if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Virtual)
                        {
                            tupleTable[row - 4, col - 4, 7] = TupleType.Virtual;
                            break;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.Black)
                        {
                            black[7]++;
                        }
                        else if (exPointStates[row + i, col - i] == ExtendedPointStateEnum.White)
                        {
                            white[7]++;
                        }
                    }
                    #endregion //check tuples of every direction

                    //decide tuple type
                    for (int i = 0; i < 8; i++)
                    {
                        //already assigned
                        if (tupleTable[row - 4, col - 4, i] == TupleType.Virtual)
                        {
                            continue;
                        }
                        if (white[i] > 0 && black[i] > 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Polluted;
                        }
                        else if (white[i] == 0 && black[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = TupleType.Blank;
                        }
                        else if (white[i] == 0)
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)black[i];
                        }
                        else
                        {
                            tupleTable[row - 4, col - 4, i] = (TupleType)(white[i] + 4);
                        }
                    }
                }
            }
            #region ---scoreTable calculate
            //calculate score table . using symmetry
            //top left corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];     //bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]]; //bottom right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];     //right
                    }
                }
            }
            //top right corner
            for (int row = 0; row < 8; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row >= m)//top left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col, 2]];     //bottom
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]]; //bottom left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];     //left
                    }
                }
            }
            //bottom left corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom right
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col + m, 1]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];     //top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col + m, 7]]; //top right
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col + m, 0]];     //right
                    }
                }
            }
            //bottom right corner
            for (int row = 8; row < 15; row++)
            {
                for (int col = 8; col < 15; col++)
                {
                    if (exPointStates[row + 4, col + 4] != ExtendedPointStateEnum.Blank)
                    {
                        //this situation has been considered
                        //scoreTable[row,col]=0;
                        continue;
                    }
                    for (int m = 0; m < 5; m++)
                    {
                        if (row + m < 15)//bottom left
                        {
                            scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row + m, col - m, 3]];
                        }
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col, 6]];     //top
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row - m, col - m, 5]]; //top left
                        scoreTable[row, col] += tupleScoreTable[(int)tupleTable[row, col - m, 4]];     //left
                    }
                }
            }
            #endregion //scoreTable

            //select best position
            List <Position> bestList = new List <Position>();

            //select first valid point
            Position first = new Position(0, 0);
            //all the point is forbidden.connot happen
            //while (IsFobidden(first))
            //{
            //    while (IsFobidden(first))
            //    {
            //        if (first.Col<14)
            //        {
            //            first.Col++;
            //        }
            //        else
            //        {
            //            break;
            //        }
            //    }
            //    if (first.Row<14)
            //    {
            //        first.Row++;
            //    }
            //    else
            //    {
            //        break;
            //    }
            //}
            while (IsFobidden(ref chessBoard, first, pieceType))
            {
                if (first.Col < 14)
                {
                    first.Col++;
                }
                else if (first.Row < 14)
                {
                    first.Row++;
                    first.Col = 0;
                }
                else
                {
                    return(new ChessBoardPoint(-1, -1));
                }
            }
            bestList.Add(first);

            Referee checkWin = new Referee();
            //select best points
            for (int row = 0; row < 15; row++)
            {
                for (int col = 0; col < 15; col++)
                {
                    if (scoreTable[row, col] > scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Clear();
                            bestList.Add(best);
                        }
                    }
                    else if (scoreTable[row, col] == scoreTable[bestList[0].Row, bestList[0].Col])
                    {
                        Position best = new Position(row, col);
                        if (!IsFobidden(ref chessBoard, best, pieceType))
                        {
                            bestList.Add(best);
                        }
                    }
                }
            }
            //there is no best .connot happen
            if (bestList.Count == 0)
            {
                return(new ChessBoardPoint(-1, -1));
            }
            Position ret = bestList[(new Random()).Next(bestList.Count)];
            return(new ChessBoardPoint(14 - ret.Row, ret.Col));
        }
Пример #37
0
 private void ClearUpData()
 {
     _referee = null;
 }
Пример #38
0
 public void No_wins_yet()
 {
     var sut = new Referee("", "");
     Assert.AreEqual("Love:Love", sut.CurrentScore);
 }
        public static void Initializer()  //KLAR
        {
            var context = new OlympicContext();

            // Looks for any sports. If Db is empty it runs below, else it skips this.
            if (context.Sports.Any())
            {
                return;   // DB has been initialized
            }

            var sport = new Sport[]
            {
                new Sport {
                    SportName = "Alpine Skiing"
                },
                new Sport {
                    SportName = "Curling"
                },
                new Sport {
                    SportName = "IceHockey"
                },
                new Sport {
                    SportName = "Snowboard"
                },
                new Sport {
                    SportName = "Speedskating"
                },
                new Sport {
                    SportName = "Nordic Combined"
                }
            };

            foreach (Sport d in sport)
            {
                context.Add(d);
            }
            context.SaveChanges();

            var country = new Country[]
            {
                new Country {
                    CountryName = "Sweden", Gold = 2, Silver = 0, Bronze = 6
                },
                new Country {
                    CountryName = "Norway", Gold = 0, Silver = 0, Bronze = 0
                },
                new Country {
                    CountryName = "Germany", Gold = 0, Silver = 2, Bronze = 0
                },
                new Country {
                    CountryName = "Russia", Gold = 0, Silver = 1, Bronze = 0
                },
                new Country {
                    CountryName = "United States", Gold = 1, Silver = 0, Bronze = 0
                },
                new Country {
                    CountryName = "Great Britain", Gold = 0, Silver = 0, Bronze = 1
                },
                new Country {
                    CountryName = "Finland", Gold = 4, Silver = 0, Bronze = 0
                },
                new Country {
                    CountryName = "Japan", Gold = 5, Silver = 1, Bronze = 0
                },
                new Country {
                    CountryName = "France", Gold = 0, Silver = 0, Bronze = 1
                }
            };

            foreach (Country d in country)
            {
                context.Add(d);
            }
            context.SaveChanges();

            var contest = new Contest[]
            {
                new Contest {
                    ContestName = "Alpine combined men", SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contest {
                    ContestName = "Giant slalom women", SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contest {
                    ContestName = "Super-G men", SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contest {
                    ContestName = "50km men", SportId = sport.Single(s => s.SportName == "Nordic Combined").Id
                },
                new Contest {
                    ContestName = "4x5km relay women", SportId = sport.Single(s => s.SportName == "Nordic Combined").Id
                },
                new Contest {
                    ContestName = "Sprint 1,5km men", SportId = sport.Single(s => s.SportName == "Nordic Combined").Id
                },
                new Contest {
                    ContestName = "Curling men ", SportId = sport.Single(s => s.SportName == "Curling").Id
                }
            };

            foreach (Contest d in contest)
            {
                context.AddRange(d);
            }
            context.SaveChanges();

            var referee = new Referee[]
            {
                new Referee {
                    Name = "Tobias Wehrli", CountryId = country.Single(s => s.CountryName == "Norway").Id
                },
                new Referee {
                    Name = "Nathan Vanoosten", CountryId = country.Single(s => s.CountryName == "Finland").Id
                },
                new Referee {
                    Name = "Dina Allen", CountryId = country.Single(s => s.CountryName == "United States").Id
                },
                new Referee {
                    Name = "Gabriella Gran", CountryId = country.Single(s => s.CountryName == "Sweden").Id
                },
                new Referee {
                    Name = "Mark Lemelin", CountryId = country.Single(s => s.CountryName == "United States").Id
                },
                new Referee {
                    Name = "Roman Gofman", CountryId = country.Single(s => s.CountryName == "Germany").Id
                }
            };

            foreach (Referee d in referee)
            {
                context.AddRange(d);
            }
            context.SaveChanges();
            var contestant = new Contestant[]
            {
                new Contestant {
                    FirstName = "Will", LastName = "Smith", Age = 26, Gender = "male", CountryId = country.Single(s => s.CountryName == "United States").Id, SportId = sport.Single(s => s.SportName == "IceHockey").Id
                },
                new Contestant {
                    FirstName = "Feng", LastName = "Shui", Age = 28, Gender = "female", CountryId = country.Single(s => s.CountryName == "Japan").Id, SportId = sport.Single(s => s.SportName == "Nordic Combined").Id
                },
                new Contestant {
                    FirstName = "Nina", LastName = "Ollinen", Age = 16, Gender = "female", CountryId = country.Single(s => s.CountryName == "Finland").Id, SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contestant {
                    FirstName = "James", LastName = "Bond", Age = 36, Gender = "male", CountryId = country.Single(s => s.CountryName == "Great Britain").Id, SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contestant {
                    FirstName = "Melinda", LastName = "Jones", Age = 20, Gender = "female", CountryId = country.Single(s => s.CountryName == "United States").Id, SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contestant {
                    FirstName = "Tryggve", LastName = "Aasheim", Age = 18, Gender = "male", CountryId = country.Single(s => s.CountryName == "Norway").Id, SportId = sport.Single(s => s.SportName == "Nordic Combined").Id
                },
                new Contestant {
                    FirstName = "Jochen", LastName = "Thewes", Age = 19, Gender = "male", CountryId = country.Single(s => s.CountryName == "Germany").Id, SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contestant {
                    FirstName = "Pjotr", LastName = "Golikov", Age = 24, Gender = "male", CountryId = country.Single(s => s.CountryName == "Russia").Id, SportId = sport.Single(s => s.SportName == "Alpine Skiing").Id
                },
                new Contestant {
                    FirstName = "Didier", LastName = "Ravault", Age = 27, Gender = "male", CountryId = country.Single(s => s.CountryName == "France").Id, SportId = sport.Single(s => s.SportName == "Nordic Combined").Id
                }
            };

            foreach (Contestant d in contestant)
            {
                context.AddRange(d);
            }
            context.SaveChanges();
            var match = new Match[]
            {
                new Domain.Match {
                    Arena = "Forest tour", DateTime = new DateTime(2018, 05, 13), ContestId = contest.Single(s => s.ContestName == "Sprint 1,5km men").Id, RefereeId = referee.Single(s => s.Name == "Tobias Wehrli").Id, ContestantId = contestant.Single(s => s.LastName == "Ravault" && s.FirstName == "Didier").Id
                },
                new Domain.Match {
                    Arena = "Death Hill", DateTime = new DateTime(2018, 05, 14), ContestId = contest.Single(s => s.ContestName == "50km men").Id, RefereeId = referee.Single(s => s.Name == "Nathan Vanoosten").Id, ContestantId = contestant.Single(s => s.LastName == "Aasheim" && s.FirstName == "Tryggve").Id
                },
                new Domain.Match {
                    Arena = "Killer Slope", DateTime = new DateTime(2018, 05, 15), ContestId = contest.Single(s => s.ContestName == "Giant slalom women").Id, RefereeId = referee.Single(s => s.Name == "Dina Allen").Id, ContestantId = contestant.Single(s => s.LastName == "Golikov" && s.FirstName == "Pjotr").Id
                },
                new Domain.Match {
                    Arena = "The Wall", DateTime = new DateTime(2018, 05, 16), ContestId = contest.Single(s => s.ContestName == "Alpine combined men").Id, RefereeId = referee.Single(s => s.Name == "Roman Gofman").Id, ContestantId = contestant.Single(s => s.LastName == "Jones" && s.FirstName == "Melinda").Id
                }
            };

            foreach (Match d in match)
            {
                context.AddRange(d);
            }
            context.SaveChanges();
        }
Пример #40
0
        public void addToFavouriteTeam(Referee referee)
        {
            Team favTeam = referee.FavouriteTeam;

            favTeam.result += 3;
        }
Пример #41
0
 public async Task <int> Add(Referee model)
 {
     return((await this.rm.Referee.Add(model)).Id);
 }
Пример #42
0
 public void AddReferees(Referee referee)
 {
     Referees.Add(referee);
 }
Пример #43
0
 public void Score_after_some_wins()
 {
     var sut = new Referee("A", "B", new[] {3, 2});
     Assert.AreEqual("40:30", sut.CurrentScore);
 }
Пример #44
0
        public static void Initialize(FootballContext context)
        {
            context.Database.EnsureCreated();

            if (context.Players.Any())
            {
                return;
            }

            var players = new Player[]
            {
                new Player {
                    Name = "Lionel"
                },
                new Player {
                    Name = "Cristiano"
                },
                new Player {
                    Name = "Iker"
                },
                new Player {
                    Name = "Gerard"
                },
                new Player {
                    Name = "Philippe"
                },
                new Player {
                    Name = "Jordi"
                },
                new Player {
                    Name = "Alejandro", YellowCard = 2
                }
            };

            foreach (var p in players)
            {
                context.Players.Add(p);
            }
            context.SaveChanges();

            var managers = new Manager[]
            {
                new Manager {
                    Name = "Alex"
                },
                new Manager {
                    Name = "Zidane"
                },
                new Manager {
                    Name = "Guardiola"
                }
            };

            foreach (var m in managers)
            {
                context.Managers.Add(m);
            }
            context.SaveChanges();

            var referees = new Referee[]
            {
                new Referee {
                    Name = "Pierluigi"
                },
                new Referee {
                    Name = "Howard"
                }
            };

            foreach (var r in referees)
            {
                context.Referees.Add(r);
            }
            context.SaveChanges();
        }
Пример #45
0
 // This method will add a Game Master if one doesn't excist, or replace the existing one.
 public void AddGameMaster(Referee referee)
 {
     if (Referees.Contains(referee))
     {
         GameMaster = referee;
     } else
     {
         Console.WriteLine("This referee does not excist in the tournament, and can therefore not be set as Game Master");
     }
 }
Пример #46
0
 /**
  *   Konstruktor.
  */
 public DwaOgnie(Rozgrywki druzynaX, Rozgrywki druzynaY, Referee sedziaGlowny)
 {
     this.druzynaX = druzynaX; this.druzynaY = druzynaY; this.sedziaGlowny = sedziaGlowny;
 }
Пример #47
0
 public void RemoveReferee(Referee referee)
 {
     Referees.Remove(referee);
 }
Пример #48
0
 internal void AddReferee(Referee referee)
 {
     referee.Stadium = this;
     Referees.Add(referee);
 }
Пример #49
0
        public void Game_still_on()
        {
            var sut = new Referee("A", "B", new[] { 3, 2 });

            Assert.AreEqual("", sut.Winner);
        }
Пример #50
0
        public void Game_has_been_won()
        {
            var sut = new Referee("A", "B", new[] { 4, 2 });

            Assert.AreEqual("A", sut.Winner);
        }
Пример #51
0
        //is forbidden
        private bool IsFobidden(ref IChessBoard chessBoard, Position point, PieceTypeEnum pieceType)
        {
            Referee platformCheck = new Referee();
            PlayStepResultEnum stepResult = platformCheck.Check(chessBoard, new ChessBoardPoint(14 - point.Row, point.Col), PieceTypeEnum.Black);
            //it seems the platform does not check four-three-three

            if (stepResult == PlayStepResultEnum.Four_Four ||
               stepResult == PlayStepResultEnum.Three_Three ||
               stepResult == PlayStepResultEnum.Overline)
            {
                if (pieceType == PieceTypeEnum.Black)
                {
                    return true;
                }
                else
                {
                    //white priority vs. black forbidden
                    //if this position is black-forbidden,generally white should not be put here
                    //but if is advantaged enough for white,it should
                    if (PlayStepResultEnum.Win == platformCheck.Check(chessBoard, new ChessBoardPoint(14 - point.Row, point.Col), PieceTypeEnum.White))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Пример #52
0
        public ActionResult Details(long tid)
        {
            //var stopWatch = System.Diagnostics.Stopwatch.StartNew();

            try
            {
                //tid = 47;

                if (_viewModel == null)
                {
                    _viewModel = new TeacherSubscriptionViewModel();
                }

                Model.Model.Teacher teacher = _da.GetModelBy <Model.Model.Teacher, TEACHER>(x => x.Person_Id == tid);
                if ((teacher != null && teacher.Person.Id > 0) && _viewModel.PersonAlreadyExist == false)
                {
                    _viewModel.Teacher = teacher;

                    _viewModel.Periods           = _da.GetAll <Period, PERIOD>();
                    _viewModel.WeekDays          = _da.GetAll <WeekDay, WEEK_DAY>();
                    _viewModel.StudentCategories = _da.GetAll <StudentCategory, STUDENT_CATEGORY>();

                    List <TeacherOLevelResultDetail> firstSittingOLevelResultDetails  = null;
                    List <TeacherOLevelResultDetail> secondSittingOLevelResultDetails = null;
                    Referee             referee     = _da.GetModelBy <Referee, TEACHER_REFEREE>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    LoginDetail         loginDetail = _da.GetModelBy <LoginDetail, PERSON_LOGIN>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    TeacherOLevelResult firstSittingOLevelResult  = _da.GetModelBy <TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 1);
                    TeacherOLevelResult secondSittingOLevelResult = _da.GetModelBy <TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 2);
                    List <TeacherEducationalQualification> teacherEducationalQualifications = _da.GetModelsBy <TeacherEducationalQualification, TEACHER_EDUCATIONAL_QUALIFICATION>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    List <TeacherEmploymentHistory>        teacherEmploymentHistories       = _da.GetModelsBy <TeacherEmploymentHistory, TEACHER_EMPLOYMENT_HISTORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    List <TeacherAward>           teacherAwards            = _da.GetModelsBy <TeacherAward, TEACHER_AWARD>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    List <TeacherStudentCategory> teacherStudentCategories = _da.GetModelsBy <TeacherStudentCategory, TEACHER_STUDENT_CATEGORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    List <TeacherAvailability>    teacherAvailabilities    = _da.GetModelsBy <TeacherAvailability, TEACHER_AVAILABILITY>(x => x.Person_Id == _viewModel.Teacher.Person.Id);



                    //_viewModel.Periods = await _da.GetAllAsync<Period, PERIOD>();
                    //_viewModel.WeekDays = await _da.GetAllAsync<WeekDay, WEEK_DAY>();
                    //_viewModel.StudentCategories = await _da.GetAllAsync<StudentCategory, STUDENT_CATEGORY>();

                    //List<TeacherOLevelResultDetail> firstSittingOLevelResultDetails = null;
                    //List<TeacherOLevelResultDetail> secondSittingOLevelResultDetails = null;
                    //Referee referee = await _da.GetModelByAsync<Referee, TEACHER_REFEREE>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    //LoginDetail loginDetail = await _da.GetModelByAsync<LoginDetail, PERSON_LOGIN>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    //TeacherOLevelResult firstSittingOLevelResult = await _da.GetModelByAsync<TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 1);
                    //TeacherOLevelResult secondSittingOLevelResult = await _da.GetModelByAsync<TeacherOLevelResult, TEACHER_O_LEVEL_RESULT>(x => x.Person_Id == _viewModel.Teacher.Person.Id && x.O_Level_Exam_Sitting_Id == 2);
                    //List<TeacherEducationalQualification> teacherEducationalQualifications = await _da.GetModelsByAsync<TeacherEducationalQualification, TEACHER_EDUCATIONAL_QUALIFICATION>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    //List<TeacherEmploymentHistory> teacherEmploymentHistories = await _da.GetModelsByAsync<TeacherEmploymentHistory, TEACHER_EMPLOYMENT_HISTORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    //List<TeacherAward> teacherAwards = await _da.GetModelsByAsync<TeacherAward, TEACHER_AWARD>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    //List<TeacherStudentCategory> teacherStudentCategories = await _da.GetModelsByAsync<TeacherStudentCategory, TEACHER_STUDENT_CATEGORY>(x => x.Person_Id == _viewModel.Teacher.Person.Id);
                    //List<TeacherAvailability> teacherAvailabilities = await _da.GetModelsByAsync<TeacherAvailability, TEACHER_AVAILABILITY>(x => x.Person_Id == _viewModel.Teacher.Person.Id);



                    if (referee != null)
                    {
                        _viewModel.Referee = referee;
                    }
                    if (loginDetail != null)
                    {
                        _viewModel.Teacher.LoginDetail = loginDetail;
                    }
                    else
                    {
                        _viewModel.Teacher.LoginDetail = new LoginDetail();
                        _viewModel.Teacher.LoginDetail.SecurityQuestion = new SecurityQuestion();
                        _viewModel.Teacher.LoginDetail.Role             = new Role();
                    }


                    if (_viewModel.Periods != null && _viewModel.Periods.Count > 0)
                    {
                        _viewModel.WeekDays.Insert(0, new WeekDay());
                    }
                    if (_viewModel.WeekDays != null && _viewModel.WeekDays.Count > 0)
                    {
                        _viewModel.Periods.Insert(0, new Period());
                    }
                    _viewModel.TeacherStudentCategories = UiUtility.InitializeStudentCategory(_viewModel.StudentCategories);
                    _viewModel.TeacherAvailabilities    = UiUtility.InitializeAvailability(_viewModel.WeekDays, _viewModel.Periods);



                    if (teacherEducationalQualifications != null && teacherEducationalQualifications.Count > 0)
                    {
                        if (_viewModel.TeacherEducationalQualifications != null && _viewModel.TeacherEducationalQualifications.Count > 0)
                        {
                            foreach (TeacherEducationalQualification educationalQualification in teacherEducationalQualifications)
                            {
                                foreach (TeacherEducationalQualification qualification in _viewModel.TeacherEducationalQualifications)
                                {
                                    if (qualification.SchoolType.Id == educationalQualification.SchoolType.Id && qualification.Id <= 0)
                                    {
                                        qualification.Id               = educationalQualification.Id;
                                        qualification.Person           = educationalQualification.Person;
                                        qualification.SchoolType       = educationalQualification.SchoolType;
                                        qualification.School           = educationalQualification.School;
                                        qualification.YearOfAdmission  = educationalQualification.YearOfAdmission;
                                        qualification.YearOfGraduation = educationalQualification.YearOfGraduation;
                                        qualification.Qualification    = educationalQualification.Qualification;

                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (firstSittingOLevelResult != null && firstSittingOLevelResult.Id > 0)
                    {
                        firstSittingOLevelResultDetails = _da.GetModelsBy <TeacherOLevelResultDetail, TEACHER_O_LEVEL_RESULT_DETAIL>(x => x.Teacher_O_Level_Result_Id == firstSittingOLevelResult.Id);
                    }
                    if (secondSittingOLevelResult != null && secondSittingOLevelResult.Id > 0)
                    {
                        secondSittingOLevelResultDetails = _da.GetModelsBy <TeacherOLevelResultDetail, TEACHER_O_LEVEL_RESULT_DETAIL>(x => x.Teacher_O_Level_Result_Id == secondSittingOLevelResult.Id);
                    }

                    if (teacherEmploymentHistories != null && teacherEmploymentHistories.Count > 0)
                    {
                        if (_viewModel.TeacherEmploymentHistories != null && _viewModel.TeacherEmploymentHistories.Count > 0)
                        {
                            for (int i = 0; i < teacherEmploymentHistories.Count; i++)
                            {
                                _viewModel.TeacherEmploymentHistories[i].Id               = teacherEmploymentHistories[i].Id;
                                _viewModel.TeacherEmploymentHistories[i].Person           = teacherEmploymentHistories[i].Person;
                                _viewModel.TeacherEmploymentHistories[i].Employer         = teacherEmploymentHistories[i].Employer;
                                _viewModel.TeacherEmploymentHistories[i].LastPositionHeld = teacherEmploymentHistories[i].LastPositionHeld;
                                _viewModel.TeacherEmploymentHistories[i].StartYear        = teacherEmploymentHistories[i].StartYear;
                                _viewModel.TeacherEmploymentHistories[i].EndYear          = teacherEmploymentHistories[i].EndYear;
                            }
                        }
                    }

                    if (teacherAwards != null && teacherAwards.Count > 0)
                    {
                        if (_viewModel.TeacherAwards != null && _viewModel.TeacherAwards.Count > 0)
                        {
                            for (int i = 0; i < teacherAwards.Count; i++)
                            {
                                _viewModel.TeacherAwards[i].Id          = teacherAwards[i].Id;
                                _viewModel.TeacherAwards[i].Person      = teacherAwards[i].Person;
                                _viewModel.TeacherAwards[i].AwardBody   = teacherAwards[i].AwardBody;
                                _viewModel.TeacherAwards[i].AwardName   = teacherAwards[i].AwardName;
                                _viewModel.TeacherAwards[i].YearAwarded = teacherAwards[i].YearAwarded;
                            }
                        }
                    }

                    if (teacherStudentCategories != null && teacherStudentCategories.Count > 0)
                    {
                        if (_viewModel.TeacherStudentCategories != null && _viewModel.TeacherStudentCategories.Count > 0)
                        {
                            foreach (TeacherStudentCategory teacherStudentCategory in _viewModel.TeacherStudentCategories)
                            {
                                List <TeacherStudentCategory> studentCategories = teacherStudentCategories.Where(x => x.StudentCategory.Id == teacherStudentCategory.StudentCategory.Id).ToList();
                                if (studentCategories != null && studentCategories.Count > 0)
                                {
                                    teacherStudentCategory.IsSelected = true;
                                    teacherStudentCategory.Person     = _viewModel.Teacher.Person;
                                }
                            }
                        }
                    }

                    if (teacherAvailabilities != null && teacherAvailabilities.Count > 0)
                    {
                        if (_viewModel.TeacherAvailabilities != null && _viewModel.TeacherAvailabilities.Count > 0)
                        {
                            foreach (TeacherAvailability teacherAvailability in _viewModel.TeacherAvailabilities)
                            {
                                List <TeacherAvailability> availabilities = teacherAvailabilities.Where(x => x.WeekDay.Id == teacherAvailability.WeekDay.Id && x.Period.Id == teacherAvailability.Period.Id).ToList();
                                if (availabilities != null && availabilities.Count > 0)
                                {
                                    teacherAvailability.IsAvailable = true;
                                    teacherAvailability.Person      = _viewModel.Teacher.Person;
                                }
                            }
                        }
                    }

                    SetTeacherFirstSittingOLevelResult(firstSittingOLevelResult, firstSittingOLevelResultDetails);
                    SetTeacherSecondSittingOLevelResult(secondSittingOLevelResult, secondSittingOLevelResultDetails);
                }

                SetPassportUrl(_viewModel.Teacher.ImageFileUrl);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                SetMessage(ex.Message, ApplicationMessage.Category.Error);
            }

            //stopWatch.Stop();
            //var executionTime = stopWatch.ElapsedMilliseconds;
            //ViewBag.Time = executionTime;

            return(View(_viewModel));
        }
Пример #53
0
 public void Game_is_over()
 {
     var sut = new Referee(new[] {"A", "B"}, new[] { 4, 2 });
     Assert.AreEqual("A", sut.Winner);
 }
Пример #54
0
 public MatchInfo()
 {
     BlueRobots   = new Robot[Const.RobotsPerTeam];
     YellowRobots = new Robot[Const.RobotsPerTeam];
     Referee      = new Referee();
 }
Пример #55
0
 public override void UnRegister(Referee referee)
 {
     Referee.wonPLayer -= Notify;
 }
 public void CreateReferee(FooteoUser user, Referee referee)
 {
     user.Referee = referee;
     this.dbContext.SaveChanges();
 }
Пример #57
0
 /// <summary>
 ///     Default constructor to initialize objects/scripts
 /// </summary>
 public GameBreak()
 {
     referee = GameObject.FindGameObjectWithTag("Referee").GetComponent<Referee>();
     ball = GameObject.FindGameObjectWithTag("Ball");
 }
Пример #58
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FootballMatch"/> class.
 /// </summary>
 /// <param name="mainReferee">The main <see cref="Referee"/>.</param>
 /// <param name="teamA">The <see cref="Team"/> a.</param>
 /// <param name="teamB">The <see cref="Team"/> b.</param>
 /// <param name="suppRef1">The first supporting <see cref="Referee"/>.</param>
 /// <param name="suppRef2">The second supporting <see cref="Referee"/>.</param>
 public FootballMatch(Referee mainReferee, Team teamA, Team teamB, Referee suppRef1, Referee suppRef2)
     : base(mainReferee, teamA, teamB)
 {
     this.suppRef1 = suppRef1;
     this.suppRef2 = suppRef2;
 }
Пример #59
0
 public static void Main () {
     Game game = new Game ();
     Referee referee = new Referee (game);
     game.Score = 70;
     game.Score = 110;
 }
Пример #60
0
        private void loadGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var doc = new XmlDocument();

                    //Load the document with the last book node.
                    var reader = new XmlTextReader(openFileDialog1.OpenFile())
                    {
                        WhitespaceHandling = WhitespaceHandling.None
                    };

                    reader.Read();

                    doc.Load(reader);

                    var matchNode = doc.GetElementsByTagName("Match");
                    var sizeNode  = matchNode.Item(0)?.ChildNodes.Item(1);

                    if (sizeNode == null)
                    {
                        Console.WriteLine(@"The file was not in the proper format.");
                        return;
                    }

                    _referee = new Referee(Convert.ToInt32(sizeNode.InnerText));

                    var firstPlayer = new Playback(1, _referee.Size, new Config());
                    var otherPlayer = new Playback(2, _referee.Size, new Config());
                    var player1Turn = 1;
                    var player2Turn = 1;
                    var moves       = doc.GetElementsByTagName("Move");
                    foreach (XmlNode move in moves)
                    {
                        var player = Convert.ToInt32(move["Player"]?.InnerText);
                        var x      = Convert.ToInt32(move["X"]?.InnerText);
                        var y      = Convert.ToInt32(move["Y"]?.InnerText);
                        if (player == 1)
                        {
                            firstPlayer.AddMove(x, y, player1Turn);
                            player1Turn++;
                        }
                        else
                        {
                            otherPlayer.AddMove(x, y, player2Turn);
                            player2Turn++;
                        }
                    }

                    _referee.Player1 = firstPlayer;
                    _referee.Player2 = otherPlayer;

                    // and feed it the moves
                    StartGame();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(@"Game couldn't be loaded properly : " + exception.Message);
                    Console.WriteLine(@"Game couldn't be loaded properly : " + exception.Message);
                }
            }
        }