Beispiel #1
0
        public void Player1MoveCausesPlayer2EliminationBeforeFirstTurn()
        {
            TestScenerios test  = new TestScenerios();
            Tile          t1    = test.makeTile(0, 2, 1, 5, 3, 4, 6, 7);
            Board         board = new Board();
            Admin         admin = new Admin();

            SPlayer p1 = new SPlayer("blue", new List <Tile>(), new RandomPlayer());

            p1.initialize(board);
            test.setStartPos(board, p1, new Posn(5, 6, 7));

            SPlayer p2 = new SPlayer("green", new List <Tile>(), new RandomPlayer());

            p2.initialize(board);
            test.setStartPos(board, p2, new Posn(5, 6, 6));

            TurnResult tr = admin.playATurn(board, t1);

            Posn p1EndPosExpected = new Posn(5, 5, 0);

            Posn p1EndPosActual = tr.currentPlayers[0].getPlayerPosn();

            Assert.IsTrue(p1EndPosExpected.isEqual(p1EndPosActual));
            Assert.IsTrue(tr.eliminatedPlayers.Exists(x => x.returnColor() == "green"));
            Assert.IsTrue(tr.playResult.Exists(x => x.returnColor() == "blue"));
        }
Beispiel #2
0
        public void MakeAMoveWhenTileIsRotated()
        {
            Admin          a      = new Admin();
            Board          b      = new Board();
            List <SPlayer> inGame = new List <SPlayer>();

            SPlayer p1 = new SPlayer("p1", new List <Tile>());

            p1.setPosn(new Posn(1, 1, 3));
            b.registerPlayer(p1);
            inGame.Add(p1);

            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 3, 6, 4, 7, 2, 1, 5);

            Tile rotatedTile = t1.rotate();

            TurnResult tr         = a.playATurn(b, rotatedTile);
            Posn       playerPosn = tr.currentPlayers[0].getPlayerPosn();

            Assert.IsTrue(playerPosn.returnCol() == 2, "p1 not at correct col");
            Assert.IsTrue(playerPosn.returnRow() == 1, "p1 not at correct row");
            Assert.IsTrue(playerPosn.returnLocationOnTile() == 0, "p1 not at correct location on tile");
            Assert.IsTrue(tr.currentPlayers.Exists(x => x.returnColor() == "p1"), "p1 not in winning players");
        }
Beispiel #3
0
        public void MakeAMoveCauseTokenToCrossMultipleTiles()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t2   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          t3   = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);
            Tile          t4   = test.makeTile(0, 1, 2, 7, 4, 5, 3, 6);

            Admin a = new Admin();
            Board b = new Board();

            SPlayer p1 = new SPlayer("p1", new List <Tile>());

            p1.setPosn(new Posn(1, 1, 3));

            b.registerPlayer(p1);

            b.grid[1, 1] = t2;
            b.grid[1, 3] = t1;
            b.grid[1, 4] = t3;

            TurnResult tr         = a.playATurn(b, t4);
            Posn       playerPosn = tr.currentPlayers[0].getPlayerPosn();

            Assert.IsTrue(playerPosn.returnRow() == 1);
            Assert.IsTrue(playerPosn.returnCol() == 4);
            Assert.IsTrue(playerPosn.returnLocationOnTile() == 3);
        }
Beispiel #4
0
        private void btnResolveOne_Click(object sender, EventArgs e)
        {
            clearDice();
            diceSound.Play();
            TurnResult result = attack.ResolveOneTurn();

            RefreshUi();
            DisplayDiceAsImage(result);

            if (result.AttackerWon)
            {
                btnResolveOne.Enabled = false;
                attack.AttackingTerritory.TakeOwnership(attack.DefendingTerritory);
                lblWinnerName.Text   = attack.AttackingTerritory.Name;
                btnNextPhase.Enabled = true;
            }
            else if (result.DefenderWon)
            {
                btnResolveOne.Enabled = false;
                lblWinnerName.Text    = attack.DefendingTerritory.Name;
                btnNextPhase.Enabled  = true;
            }

            this.Parent.Refresh();
        }
Beispiel #5
0
        public void boardToXMLPlayerEliminatedCurrentTurn()
        {
            Admin         a     = new Admin();
            Board         board = new Board();
            TestScenerios test  = new TestScenerios();

            // Board set up
            Tile normalTile      = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile eliminationTile = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile drawPileTile    = test.makeTile(0, 3, 2, 1, 4, 7, 6, 5);

            board.grid[0, 0] = normalTile;
            board.addTileToDrawPile(drawPileTile);

            // Player set up
            SPlayer eliminatedPlayer = new SPlayer("blue", new List <Tile>(), new RandomPlayer());

            eliminatedPlayer.initialize(board);
            test.setStartPos(board, eliminatedPlayer, new Posn(3, -1, 3));

            SPlayer activePlayer = new SPlayer("red", new List <Tile>(), new RandomPlayer());

            activePlayer.initialize(board);
            test.setStartPos(board, activePlayer, new Posn(0, 0, 3));

            TurnResult tmpturn = a.playATurn(board, eliminationTile);

            // Test
            XElement boardToXMLActual   = XMLEncoder.boardToXML(tmpturn.b);
            XElement boardToXMLExpected = XElement.Parse("<board><map><ent><xy><x>0</x><y>0</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>4</n></connect><connect><n>3</n><n>6</n></connect><connect><n>5</n><n>7</n></connect></tile></ent><ent><xy><x>0</x><y>3</y></xy><tile><connect><n>0</n><n>1</n></connect><connect><n>2</n><n>3</n></connect><connect><n>4</n><n>5</n></connect><connect><n>6</n><n>7</n></connect></tile></ent></map><map><ent><color>red</color><pawn-loc><v></v><n>1</n><n>1</n></pawn-loc></ent><ent><color>blue</color><pawn-loc><v></v><n>0</n><n>6</n></pawn-loc></ent></map></board>");

            Assert.IsTrue(XNode.DeepEquals(boardToXMLActual, boardToXMLExpected));
        }
Beispiel #6
0
        public void DragonTileBeforeTurnStillNoNewTiles()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 2, 1, 6, 3, 5, 4, 7);
            Tile          t2   = test.makeTile(0, 1, 2, 7, 3, 4, 5, 6);

            Admin a = new Admin();
            Board b = new Board();

            SPlayer p1 = new SPlayer("p1", new List <Tile>());

            p1.setPosn(new Posn(1, 0, 2));

            SPlayer p2 = new SPlayer("p2", new List <Tile>());

            p2.setPosn(new Posn(0, 1, 5));

            SPlayer p3 = new SPlayer("p3", new List <Tile>());

            p3.setPosn(new Posn(1, 2, 6));

            b.registerPlayer(p1);
            b.registerPlayer(p2);
            b.registerPlayer(p3);

            b.grid[1, 2] = t2;

            TurnResult tr = a.playATurn(b, t1);

            Assert.IsTrue(tr.b.isDragonTileHolder("p1"));
            Assert.IsTrue(tr.currentPlayers[0].returnHand().Count == 0);
            Assert.IsTrue(tr.currentPlayers[1].returnHand().Count == 0);
            Assert.IsTrue(tr.currentPlayers[2].returnHand().Count == 0);
        }
        /// <summary>
        /// GUI logic for a turn
        /// </summary>
        /// <param name="Result">Result of Turn()</param>
        /// <returns>If a button should be active</returns>
        private void evaluateTurn(TurnResult Result)
        {
            switch (Result)        // wertet den Parameter Result aus
            {
            case TurnResult.Valid: // wenn der zug gültig war
                redrawField();     // spielfeld aktualisieren
                Message = $"Spieler {(logic.GetCurrentPlayer() ? "X" : "O")} ist am Zug";
                break;

            case TurnResult.Win:                                                                  // wenn der zug zum sieg geführt hat
                redrawField();                                                                    // spielfeld aktualisieren
                Message = $"Sieg! Spieler {(logic.GetCurrentPlayer() ? "X" : "O")} hat gewonnen"; // nachricht ausgeben das der aktuelle spieler gewonnen hat

                // alle button deaktivieren, da das Spiel vorbei ist
                foreach (var item in buttonArray)
                {
                    item.IsEnabled = false;
                }
                break;

            case TurnResult.Tie:            // wenn der zug zu einem unentschieden geführt hat
                redrawField();              // spielfeld aktualisieren
                Message = "Unentschieden!"; // Spieler benachrichtigen
                break;

            default:     // wenn der zug ungültig war (sollte nicht auftreten)
                Message = "Das war nix";
                break;
            }
        }
        public void TurnResultTestBunco()
        {
            TurnResult t      = new TurnResult(1, 1, 1, 1);
            int        result = t.Score;

            Assert.AreEqual(21, result);
        }
Beispiel #9
0
        public void EndOfGameFrom35TilesBeingPlaced()
        {
            TestScenerios test   = new TestScenerios();
            Board         board  = new Board();
            Admin         admin  = new Admin();
            Tile          t1     = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);
            Tile          t_play = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    board.placeTileAt(t1, i, j);
                }
            }

            // Clear two tiles
            board.placeTileAt(null, 2, 3);
            board.placeTileAt(null, 2, 4);

            SPlayer p1 = test.createPlayerAtPos("green", new List <Tile> {
            }, new RandomPlayer(), new Posn(2, 2, 2), board);
            SPlayer p2 = test.createPlayerAtPos("sienna", new List <Tile> {
            }, new RandomPlayer(), new Posn(2, 2, 3), board);

            admin.addToActivePlayers(p1);
            admin.addToActivePlayers(p2);

            TurnResult tr = admin.playATurn(board, t_play);

            Assert.IsTrue(tr.playResult != null);
        }
Beispiel #10
0
        public void TurnResultTestBinky()
        {
            TurnResult t      = new TurnResult(1, 2, 2, 2);
            int        result = t.Score;

            Assert.AreEqual(5, result);
        }
Beispiel #11
0
        public void GetTurnResultOfEndOfGameFrom35TilesBeingPlaced()
        {
            TestScenerios test  = new TestScenerios();
            Board         board = test.createBoardWithDrawPile(new List <Tile> {
            });
            Tile t1             = test.makeTile(0, 1, 2, 3, 4, 5, 6, 7);

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    board.grid[i, j] = t1;
                }
            }
            board.grid[1, 1] = null;

            SPlayer p1 = test.createPlayerAtPos("green", new List <Tile> {
            }, new RandomPlayer(), new Posn(2, 2, 2), board);
            SPlayer p2 = test.createPlayerAtPos("sienna", new List <Tile> {
            }, new RandomPlayer(), new Posn(2, 2, 3), board);

            board.setDragonTileHolder(p1);
            TurnResult tr = board.GetTurnResult();

            Assert.IsTrue(tr.playResult != null);
        }
Beispiel #12
0
        public DirectionEnum Solve2(PlayerSessionInfo info, TurnResult turn)
        {
            Location currentLocation = info.CurrentLocation;

            if (turn != null)
            {
                currentLocation = turn.Location;
            }
            var sosedi = info.NeighbourCells;

            if (turn != null)
            {
                sosedi = turn.VisibleCells;
            }

            var checker = new MovementChecker();

            var dir = lastDir;

            while (!checker.CanMove(dir, currentLocation, sosedi, 4))
            {
                dir = dir.Next();
            }
            return(dir);


            return(DirectionEnum.East);
        }
Beispiel #13
0
        public override ActionResult Perform(ITurnable turnable, TurnResult result)
        {
            Creature creature = turnable as Creature;

            if (X != 0)
            {
                creature.SpriteEffect = X > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
            }

            int newX = creature.X + X;
            int newY = creature.Y + Y;

            if (!creature.Map.InBounds(newX, newY) || creature.Map.GetTile(newX, newY).IsSolid)
            {
                result.AddEvent(new BumpEvent(X, Y, 9f, creature));
                return(Succeed());
            }

            Creature other = creature.Map.GetCreature(newX, newY);

            if (other != null)
            {
                result.AddEvent(new BumpEvent(X, Y, 9f, creature));
                return(Succeed());
            }

            result.AddEvent(new MoveEvent(creature, creature.X, creature.Y, newX, newY, 4f, 0.3f));
            creature.X += X;
            creature.Y += Y;

            return(Succeed());
        }
Beispiel #14
0
        public override void Update(float delta)
        {
            if (!_player.UnlockCamera)
            {
                _camera.Approach(new Vector2(_player.RenderX, _player.RenderY), 0.25f);
            }

            _soundEffectManager.Update();
            _lightingManager.Update(delta);

            _mapRenderer.Update(delta);
            _effectsRenderer.Update(delta);

            _map.Update(delta);

            if (!_eventManager.HasEventsToProcess())
            {
                _turnResult = _turnManager.Process();
                _eventManager.AddEvents(_turnResult.Events);

                if (_turnResult.MadeProgress)
                {
                    _map.ClearFov();
                    _fov.RefreshVisibility(new Point2D(_player.X, _player.Y), 8);
                }
            }

            _eventManager.Update(delta);
            _interfaceRenderer.Update(delta);
        }
Beispiel #15
0
        public virtual TurnResult StartTurn()
        {
            _currentlyTakingTurn = true;

            bool ignoreTurn = false;
            bool endTurn    = false;

            List <int> behaviorsCopy = new List <int>(_actorBehaviors);

            foreach (int b in behaviorsCopy)
            {
                TurnResult result = _scene.GetGameObjectPool().GetActorBehavior(b).OnActorStartTurn();
                ignoreTurn |= result == TurnResult.IGNORE_TURN;
                endTurn    |= result == TurnResult.GOTO_ENDTURN;
            }

            if (ignoreTurn)
            {
                return(TurnResult.IGNORE_TURN);
            }
            if (endTurn)
            {
                return(TurnResult.GOTO_ENDTURN);
            }

            return(TurnResult.GOTO_TAKETURN);
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World, I'm clueless!");
            Console.WriteLine("How many players are playing?");

            string input = Console.ReadLine();

            try
            {
                int        currentplayer = Int32.Parse(input);
                Game       game          = new Game();
                TurnResult res           = game.StartGame(currentplayer);

                currentplayer = res.nextplayer;

                while (!res.accusationSuccessful)
                {
                    res = PlayRound(game, res);
                }

                if (res.accusationSuccessful)
                {
                    Console.WriteLine("Player {0} solved the riddle!", res.nextplayer);
                }
            }
            catch (FormatException fex)
            {
                Console.WriteLine("That's not a number.");
            }
        }
Beispiel #17
0
 void ParseResult(TurnResult result)
 {
     if (result == TurnResult.AiWin)
     {
         aiScore++;
         RefreshScore();
         NewGame(false);
     }
     else if (result == TurnResult.HumanWin)
     {
         playerScore++;
         RefreshScore();
         NewGame(false);
     }
     else if (result == TurnResult.None)
     {
         currentTurn = (currentTurn == 0) ? 1 : 0;
         if (currentTurn == AI_TURN)
         {
             BotTurn();
         }
     }
     else
     {
         NewGame(false);
     }
 }
Beispiel #18
0
        public override TurnResult StartTurn()
        {
            foreach (MonsterAbility m in Abilities)
            {
                m.CooldownTick();
            }

            TurnResult result = base.StartTurn();

            if (result == TurnResult.IGNORE_TURN || result == TurnResult.GOTO_ENDTURN)
            {
                _currentlyTakingTurn = false;
                _currentEnergy      -= MovementEnergyCost;
                return(result);
            }

            //If we can't see the player and don't know where the player might be, sleep
            if (LastKnownPlayerPosition == null ||
                LastKnownPlayerPosition.Equals(Position))
            {
                if (!_scene.IsTileVisibleFromLocation(Position, _scene.GetStudent().Position, SightRange))
                {
                    _currentlyTakingTurn = false;
                    _currentEnergy      -= MovementEnergyCost;
                    return(TurnResult.IGNORE_TURN);
                }
            }


            return(TurnResult.GOTO_TAKETURN);
        }
Beispiel #19
0
    void OnEndTurn(TurnResult result)
    {
        // give a player another build phase turn if their balls are all gone
        int winner_num = ScoreManager.instance.CheckScore();

        Player player_1 = TurnManager.instance.players[0];
        Player player_2 = TurnManager.instance.players[1];

        if (winner_num == 0 || winner_num == 1)
        {
            WinGame(winner_num);
        }
        else
        {
            int    next_player_num = TurnManager.instance.currentPlayerIndex;
            Player next_player     = TurnManager.instance.players[next_player_num];

            // handle turn conditions
            if (currentRound < buildThreshold)
            {
                TurnManager.instance.NextTurn(TurnResult.Build);
                return;
            }
            // handle result
            if (result == TurnResult.Default)
            {
                TurnManager.instance.NextTurn(TurnResult.Default);
                return;
            }
        }
    }
Beispiel #20
0
    IEnumerator GameFinish(TurnResult t)
    {
        yield return(new WaitForSeconds(1.5f));

        if (t == TurnResult.turnLose)
        {
            if (!playOneTime)
            {
                SoundControll.Instance.PlayEffecSound(SoundControll.Instance.youLose);
                playOneTime = true;
            }
            Time.timeScale = 0;
            gaveLosePanel.SetActive(true);
        }
        if (t == TurnResult.turnWin)
        {
            if (!playOneTime)
            {
                SoundControll.Instance.PlayEffecSound(SoundControll.Instance.youWin);
                playOneTime = true;
            }
            expText.text  = enemy.enemyGameobject.GetComponent <EnemyAttr>().enemy.exp.ToString();
            goldText.text = enemy.enemyGameobject.GetComponent <EnemyAttr>().enemy.gold.ToString();
            gaveWinPanel.SetActive(true);
            GlobalValue.instance.level[GlobalValue.instance.nowLevel]          = true;
            GlobalValue.instance.gameSave.level[GlobalValue.instance.nowLevel] = GlobalValue.instance.level[GlobalValue.instance.nowLevel];
            CheckQuest();
            GlobalValue.instance.SaveAllData();
        }
    }
Beispiel #21
0
        public void PlayerOrderUpdatesAfterEndOfTurnWithElimination()
        {
            TestScenerios test = new TestScenerios();
            Board         b    = new Board();
            Admin         a    = new Admin();

            SPlayer p1 = test.createPlayerAtPos("blue", new List <Tile>(), new RandomPlayer(),
                                                new Posn(-1, 0, 5), b);
            SPlayer p2 = test.createPlayerAtPos("hotpink", new List <Tile>(), new RandomPlayer(),
                                                new Posn(0, -1, 3), b);
            SPlayer p3 = test.createPlayerAtPos("green", new List <Tile>(), new RandomPlayer(),
                                                new Posn(4, 2, 1), b);

            a.addToActivePlayers(p1);
            a.addToActivePlayers(p2);
            a.addToActivePlayers(p3);

            Tile t1 = test.makeTile(0, 3, 6, 1, 2, 5, 4, 7);

            TurnResult tr = a.playATurn(b, t1);

            Assert.AreEqual(2, tr.currentPlayers.Count);
            Assert.AreEqual(1, tr.eliminatedPlayers.Count);
            Assert.AreEqual("hotpink", tr.eliminatedPlayers[0].getColor());
            Assert.AreEqual("green", tr.currentPlayers[0].getColor());
            Assert.AreEqual("blue", tr.currentPlayers[1].getColor());
        }
Beispiel #22
0
        public void DragonHolderDoesntDrawEmptyDrawPile()
        {
            TestScenerios test = new TestScenerios();
            Board         b    = new Board();
            Admin         a    = new Admin();

            SPlayer p1 = test.createPlayerAtPos("blue", new List <Tile>(), new RandomPlayer(),
                                                new Posn(-1, 0, 5), b);
            SPlayer p2 = test.createPlayerAtPos("hotpink", new List <Tile>(), new RandomPlayer(),
                                                new Posn(0, -1, 3), b);
            SPlayer p3 = test.createPlayerAtPos("green", new List <Tile>(), new RandomPlayer(),
                                                new Posn(4, 2, 1), b);

            a.addToActivePlayers(p1);
            a.addToActivePlayers(p2);
            a.addToActivePlayers(p3);

            a.setDragonTileHolder(p2);

            Tile t1 = test.makeTile(0, 3, 6, 1, 2, 5, 4, 7);

            TurnResult tr = a.playATurn(b, t1);

            Assert.AreEqual(0, p2.getHand().Count);
        }
Beispiel #23
0
        public void Player1MoveCausesPlayer2MovementBeforeFirstTurn()
        {
            TestScenerios test  = new TestScenerios();
            Tile          t1    = test.makeTile(0, 2, 1, 5, 3, 7, 4, 6);
            Board         board = new Board();
            Admin         admin = new Admin();

            SPlayer p1 = new SPlayer("blue", new List <Tile>(), new RandomPlayer());

            board.addPlayerToBoard(p1.getColor(), new Posn(5, 6, 7));

            SPlayer p2 = new SPlayer("green", new List <Tile>(), new RandomPlayer());

            board.addPlayerToBoard(p2.getColor(), new Posn(5, 6, 6));

            admin.addToActivePlayers(p1);
            admin.addToActivePlayers(p2);

            TurnResult tr = admin.playATurn(board, t1);

            Posn p1EndPosExpected = new Posn(5, 5, 0);
            Posn p2EndPosExpected = new Posn(5, 5, 7);

            Posn p1EndPosActual = board.getPlayerPosn(tr.currentPlayers[1].getColor());
            Posn p2EndPosActual = board.getPlayerPosn(tr.currentPlayers[0].getColor());


            Assert.IsTrue(p1EndPosExpected.isEqual(p1EndPosActual));
            Assert.IsTrue(p2EndPosExpected.isEqual(p2EndPosActual));
        }
Beispiel #24
0
        public void DragonTileBeforeTurnStillNoNewTiles()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 2, 1, 6, 3, 5, 4, 7);
            Tile          t2   = test.makeTile(0, 1, 2, 7, 3, 4, 5, 6);

            Admin a = new Admin();
            Board b = new Board();

            SPlayer p1 = new SPlayer("blue", new List <Tile>());

            b.addPlayerToBoard(p1.getColor(), new Posn(1, 0, 2));


            SPlayer p2 = new SPlayer("green", new List <Tile>());

            b.addPlayerToBoard(p2.getColor(), new Posn(0, 1, 5));

            SPlayer p3 = new SPlayer("hotpink", new List <Tile>());

            b.addPlayerToBoard(p3.getColor(), new Posn(1, 2, 6));

            a.addToActivePlayers(p1);
            a.addToActivePlayers(p2);
            a.addToActivePlayers(p3);

            b.placeTileAt(t2, 1, 2);

            TurnResult tr = a.playATurn(b, t1);

            Assert.IsTrue(a.isDragonHolder("blue"));
            Assert.IsTrue(tr.currentPlayers[0].getHand().Count == 0);
            Assert.IsTrue(tr.currentPlayers[1].getHand().Count == 0);
            Assert.IsTrue(tr.currentPlayers[2].getHand().Count == 0);
        }
Beispiel #25
0
        public void MakeAMoveCauseTokenToCrossMultipleTiles()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t2   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          t3   = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);
            Tile          t4   = test.makeTile(0, 1, 2, 7, 4, 5, 3, 6);

            Admin a = new Admin();
            Board b = new Board();

            SPlayer p1 = new SPlayer("blue", new List <Tile>());

            b.addPlayerToBoard(p1.getColor(), new Posn(1, 1, 3));

            a.addToActivePlayers(p1);

            b.placeTileAt(t2, 1, 1);
            b.placeTileAt(t1, 1, 3);
            b.placeTileAt(t3, 1, 4);

            TurnResult tr         = a.playATurn(b, t4);
            Posn       playerPosn = b.getPlayerPosn(tr.currentPlayers[0].getColor());

            Assert.IsTrue(new Posn(1, 4, 3).isEqual(playerPosn));
        }
Beispiel #26
0
        public void ValidTurnCausePlayerToBeEliminated()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t2   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          t3   = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);

            List <Tile> drawpile = test.makeDrawPile(t2, t3);
            Admin       a        = test.createAdminWithDrawPile(drawpile);
            Board       b        = new Board();

            SPlayer p1    = new SPlayer("p1", new List <Tile>());
            Posn    p1Pos = new Posn(0, 1, 6);

            test.setStartPos(b, p1, p1Pos);
            SPlayer p2    = new SPlayer("p2", new List <Tile>());
            Posn    p2Pos = new Posn(4, 4, 0);

            test.setStartPos(b, p2, p2Pos);

            a.addToActivePlayers(p1);
            a.addToActivePlayers(p2);

            TurnResult tmpturn = a.playATurn(b, t1);

            Assert.AreEqual(1, a.numEliminated(), "count of eliminated players has not increased to 1");
            Assert.IsTrue(tmpturn.eliminatedPlayers.Count == 1, "count of eliminated players has not increased to 1");
            Assert.IsTrue(tmpturn.eliminatedPlayers.Exists(x => x.getColor() == "p1"), "p1 has not been moved to eliminated players");
            Assert.IsFalse(tmpturn.currentPlayers.Exists(x => x.getColor() == "p1"), "p1 has not been removed from current players");
            Assert.IsTrue(tmpturn.currentPlayers.Count == 1, "count of current players has not decreased to 1");
        }
Beispiel #27
0
        public void PlayAValidTurnChangesOrderOfInGamePlayers()
        {
            TestScenerios test = new TestScenerios();
            Tile          t1   = test.makeTile(0, 1, 2, 4, 3, 6, 5, 7);
            Tile          t2   = test.makeTile(0, 6, 1, 5, 2, 4, 3, 7);
            Tile          t3   = test.makeTile(0, 5, 1, 4, 2, 7, 3, 6);

            List <Tile> drawpile = test.makeDrawPile(t2, t3);
            Admin       a        = test.createAdminWithDrawPile(drawpile);
            Board       b        = new Board();

            SPlayer p1    = new SPlayer("blue", new List <Tile>());
            Posn    p1Pos = new Posn(0, 0, 3);
            SPlayer p2    = new SPlayer("green", new List <Tile>());
            Posn    p2Pos = new Posn(4, 4, 0);

            a.addToActivePlayers(p1);
            a.addToActivePlayers(p2);

            b.addPlayerToBoard("blue", p1Pos);
            b.addPlayerToBoard("green", p2Pos);

            List <SPlayer> l1 = new List <SPlayer>()
            {
                p1, p2
            };

            List <SPlayer> l2 = new List <SPlayer>();

            TurnResult tmpturn = a.playATurn(b, t1);

            Assert.IsTrue(tmpturn.currentPlayers[0].getColor() == "green");
            Assert.IsTrue(tmpturn.currentPlayers[1].getColor() == "blue");
            Assert.IsTrue(tmpturn.currentPlayers.Count == 2);
        }
Beispiel #28
0
        public void TurnResultTestTwoCorrect()
        {
            TurnResult t      = new TurnResult(1, 1, 2, 1);
            int        result = t.Score;

            Assert.AreEqual(2, result);
        }
Beispiel #29
0
        static TurnResult PlayRound(Game game, TurnResult res)
        {
            Console.WriteLine("Player{0}s Turn.", res.nextplayer);

            if (res.nextphase == 0)
            {
                Console.WriteLine("what room do you want to move?");
                string room = Console.ReadLine();
                res = game.Play(FirstAction.Move, room);

                if (res.accepted)
                {
                    Console.WriteLine("You moved to the {0}.", room);
                }
            }
            else if (res.nextphase == 1)
            {
                Console.WriteLine("Make a suggestion. Person:");
                string person = Console.ReadLine();
                Console.WriteLine("Item: ");
                string item = Console.ReadLine();

                res = game.Play(SecondAction.Suggest, person, item, "");
                if (res.accepted && res.suggestion != null)
                {
                    if (res.suggestion.revealedCard != null)
                    {
                        Console.WriteLine("The {0} was revealed to you by Player {1}", res.suggestion.revealedCard.name,
                                          res.nextplayer + res.suggestion.playersAsked);
                    }
                    else
                    {
                        Console.WriteLine("Nobody was able to help you.");
                    }
                }
            }
            else if (res.nextphase == 2)
            {
                Console.WriteLine("Want to accuse Someone? (y/n)");
                string accuse = Console.ReadLine();
                if (accuse.Contains("y"))
                {
                    Console.WriteLine("Make a accusation. Person:");
                    string person = Console.ReadLine();
                    Console.WriteLine("Item: ");
                    string item = Console.ReadLine();
                    Console.WriteLine("Room: ");
                    string room = Console.ReadLine();

                    res = game.Play(SecondAction.Accuse, person, item, room);
                }
                else
                {
                    res = game.Play(SecondAction.Pass, "", "", "");
                }
            }

            return(res);
        }
Beispiel #30
0
        public TurnResult CalculateResult()
        {
            var winAmount = CalculateWinAmount();

            var result = new TurnResult(CheckForEnd(winAmount), winAmount);

            return(result);
        }
        public BoardViewModel()
        {
            board = Board.From(new[] { "!", "N", ",", "K", "#", "v", "w", "z", "A" });
            board.TurnEnded += Board_TurnEnded;
            currentTurnResult = TurnResult.Pending;

            Cards = new List<CardViewModel>(board.Select((c,i) => new CardViewModel(c,i)));
            TurnUp = new MvxCommand<int>(async (p) => await TurnUpActionAsync(p));
        }
        async void Board_TurnEnded(object sender, TurnResultEventArgs args)
        {
            currentTurnResult = args.Result;

            using (args.GetDeferral())
            {
                if (currentTurnResult != TurnResult.Pending)
                {
                    await Task.Delay(2000);
                    currentTurnResult = TurnResult.Pending;
                }
            }
        }
Beispiel #33
0
        public void OnTurnEnd(TurnResult turnResult, Sign sign, Field field)
        {
            if (turnResult == TurnResult.Wrong)
            {
                this.WrongTurnEval(sign);
                return;
            }

            switch (field)
            {
                case Field.A1:
                    GameHelper.MakeTurn(_window.buttonA1, sign);
                    break;
                case Field.A2:
                    GameHelper.MakeTurn(_window.buttonA2, sign);
                    break;
                case Field.A3:
                    GameHelper.MakeTurn(_window.buttonA3, sign);
                    break;
                case Field.B1:
                    GameHelper.MakeTurn(_window.buttonB1, sign);
                    break;
                case Field.B2:
                    GameHelper.MakeTurn(_window.buttonB2, sign);
                    break;
                case Field.B3:
                    GameHelper.MakeTurn(_window.buttonB3, sign);
                    break;
                case Field.C1:
                    GameHelper.MakeTurn(_window.buttonC1, sign);
                    break;
                case Field.C2:
                    GameHelper.MakeTurn(_window.buttonC2, sign);
                    break;
                case Field.C3:
                    GameHelper.MakeTurn(_window.buttonC3, sign);
                    break;
            }

            if (turnResult == TurnResult.Win)
                MessageBox.Show(string.Format("Player {0} win.", sign), "End of game");
        }
Beispiel #34
0
 public void GameOver(TurnResult result)
 {
     //Clean everything up
 }
        //must be implemented by all logic driver's
        // return true if it is done finding its next move
        public override TurnResult GetNextMove(CheckersGameDriver gameDriver)
        {
            if (_logicThread == null)
            {
                //starts up a new thread if it isnt already running and tells it to run alpha-beta search
                _finalResult = TurnResult.NotDone;
                _logicThread = new Thread(() =>
                                              {
                                                  ResetCounts();
                                                  AlphaBetaStartTime = DateTime.Now;

                                                  var maxDepth = 0;
                                                  var move = AlphaBeta(gameDriver.Board, ref maxDepth);
                                                  if (move != null)
                                                  {
                                                      var result = gameDriver.Board.MovePiece(move, Color);

                                                      _finalResult = result;
                                                  }
                                              });
                _logicThread.Start();
            }
            else
            {
                //if there is indeed a thread running, if it is done, then we are done and return the finalResult
                if(!_logicThread.IsAlive)
                {
                    _logicThread.Join();
                    _logicThread = null;
                }
            }

            return _finalResult;
        }
 public GameOverEventArgs(string gameId, TurnResult winner)
 {
     GameId = gameId;
     Winner = winner;
 }
Beispiel #37
0
 private void OnGameOver(string gameId, TurnResult winner)
 {
     var gameOverEvent = GameOver;
     if (gameOverEvent != null)
         gameOverEvent(this, new GameOverEventArgs(gameId, winner));
 }
 public TurnResultEventArgs(TurnResult result)
 {
     Result = result;
 }