Beispiel #1
0
    void Start()
    {
        compPlayer = gameObject.AddComponent <CompPlayer> ();

        InitBoard();
        UpdateUI();

        newGameButton.interactable = true;
    }
Beispiel #2
0
        /// <summary>
        /// Gets called when the player is of type Computer.
        /// </summary>
        /// <param name="player">The type of player that use the IPlayer interface.</param>
        private static void OnComputerActionTaken(CompPlayer player)
        {
            Node  target;
            Piece selectedPiece;

            FindOptimalPlay(player, out target, out selectedPiece);
            if (target != null && selectedPiece != null)
            {
                Piece.MovePiece(selectedPiece, selectedPiece.NodeReference, target);
                player.EndTurn = true;
            }
        }
Beispiel #3
0
        // GET: Scores/Create
        public ActionResult Create(int compID, int userID, int courseID, string teeColour, int SSS, DateTime rndDate, string scorecardImage, int imageID)
        {
            // Set default Values for the CompScore model initial view
            var scoresModel = new CompScore();

            // Get compPlayerID
            var pStats       = new PlayerStats();
            int compPlayerID = pStats.GetcompPlayerID(userID, compID);

            // Populate the ScoresModel
            scoresModel.CompID       = compID;
            scoresModel.CourseID     = courseID;
            scoresModel.CompPlayerID = compPlayerID;
            scoresModel.TeeColour    = teeColour;
            scoresModel.SSS          = SSS;
            scoresModel.ImageID      = imageID;

            ViewBag.RndDate   = rndDate;
            ViewBag.cardImage = scorecardImage;

            // Get Competition Name
            CompMain compMain = db.CompMains.Find(compID);

            ViewBag.CompName = compMain.CompName;
            ViewBag.CompID   = compID;

            // Get Player Name
            CompPlayer compPlayer = db.CompPlayers.Find(compPlayerID);
            User       users      = db.Users.Find(userID);

            ViewBag.PlayerName = users.UserName;

            // Get Players Current Handicap
            ViewBag.Hcap  = pStats.CurrentHcap(compPlayerID);
            ViewBag.PHcap = Math.Round(ViewBag.HCap, MidpointRounding.AwayFromZero);

            // Get Club Names For Drop Down List
            var courseInfo = new CourseInfo();

            ViewBag.CourseList = courseInfo.GetCourseList();

            // Populate variable to Tee Colour ddl
            ViewBag.TeeColourList = new SelectList(new[]
            {
                new { ID = "White", Name = "White" },
                new{ ID = "Yellow", Name = "Yellow" },
                new{ ID = "Red", Name = "Red" },
            }, "ID", "Name");

            return(View(scoresModel));
        }
 protected override void Awake()
 {
     base.Awake();
     _player = GetComponent <CompPlayer>();
 }
        static void Main(string[] args)
        {
            int humanWins  = 0;
            int compWins   = 0;
            int totalGames = 0;

            Console.WriteLine("\nWelcome to Rock Paper Scissors game. \nPlease enter your name.");
            string userName = Console.ReadLine();

            Console.WriteLine($"\n{userName}, choose your opponent: \n1. Chris\n2. Josh ");
            string      opponentChoice = Console.ReadLine();
            Player      CompPlayer     = null;
            HumanPlayer HumanPlayer    = new HumanPlayer(userName);

            if (opponentChoice == "1")
            {
                CompPlayer = new ChrisPlayer();
            }
            else if (opponentChoice == "2")
            {
                CompPlayer = new JoshPlayer();
            }

            do
            {
                Roshambo humansChoice = HumanPlayer.GenerateRoshambo();
                Roshambo compChoice   = CompPlayer.GenerateRoshambo();
                Console.WriteLine("___________________");
                Console.WriteLine($"{HumanPlayer.Name}: {humansChoice}");
                Console.WriteLine($"{CompPlayer.Name}:  {compChoice}");
                Console.WriteLine("___________________");

                Console.Write("------------------------------");


                string judgeCall;
                if ((int)humansChoice == 1 && (int)compChoice == 1)
                {
                    judgeCall = "*TIE*";
                    totalGames++;
                }
                else if ((int)humansChoice == 1 && (int)compChoice == 2)
                {
                    judgeCall = "*LOSE*";
                    compWins++;
                    totalGames++;
                }
                else if ((int)humansChoice == 1 && (int)compChoice == 3)
                {
                    judgeCall = "*WIN*";
                    humanWins++;
                    totalGames++;
                }
                else if ((int)humansChoice == 2 && (int)compChoice == 1)
                {
                    judgeCall = "*WIN*";
                    humanWins++;
                    totalGames++;
                }
                else if ((int)humansChoice == 2 && (int)compChoice == 2)
                {
                    judgeCall = "*TIE*";
                    totalGames++;
                }
                else if ((int)humansChoice == 2 && (int)compChoice == 3)
                {
                    judgeCall = "*LOSE*";
                    compWins++;
                    totalGames++;
                }
                else if ((int)humansChoice == 3 && (int)compChoice == 1)
                {
                    judgeCall = "*LOSE*";
                    compWins++;
                    totalGames++;
                }
                else if ((int)humansChoice == 3 && (int)compChoice == 2)
                {
                    judgeCall = "*WIN*";
                    humanWins++;
                    totalGames++;
                }
                else if ((int)humansChoice == 3 && (int)compChoice == 3)
                {
                    judgeCall = "*TIE*";
                    totalGames++;
                }
                else
                {
                    judgeCall = "I smell a rat";
                }
                int humanPercent = (humanWins * 100) / totalGames;
                int compPercent  = (compWins * 100) / totalGames;
                int ties         = totalGames - (humanWins + compWins);
                int tiePercent   = (ties * 100) / totalGames;
                Console.WriteLine(judgeCall + $"\nYour winning percentage: \t{humanPercent}%\t({humanWins}/{totalGames})" +
                                  $"\n{CompPlayer.Name}'s winning percentage: \t{compPercent}%\t({compWins}/{totalGames})" +
                                  $"\n                     Ties:    \t{tiePercent}%\t({ties}/{totalGames})  ");
            }while (Console.ReadLine() == "");
        }
Beispiel #6
0
        /// <summary>
        /// Attemps to find an optimal play for the computer.
        /// </summary>
        /// <param name="player"> Who the current owner is.</param>
        /// <param name="target"> Returns the destinaton of said optimal play</param>
        /// <param name="selectedPiece">Returns a chosen piece to be moved in the optimal play</param>
        static void FindOptimalPlay(IPlayer player, out Node target, out Piece selectedPiece)
        {
            Piece _selectedPiece = null;
            Node  _target        = null;

            // float minValue = float.MaxValue;
            selectedPiece = _selectedPiece;
            target        = _target;
            Board        bestBoard   = new Board();
            List <Board> simulation  = new List <Board>();
            List <Board> listOfPaths = CompPlayer.FindAllPossiblePaths(2, player, false, BoardManager.board, simulation);

            if (listOfPaths.Count <= 0)
            {
                return;
            }
            bestBoard = listOfPaths[0];
            //Debug.Log ($"The list of all available moves is {listOfPaths.Count} long and the current best board is {bestBoard} at {bestBoard.value}.");
            List <Piece> bestBoardPieces = new List <Piece>();
            List <Piece> boardPieces     = new List <Piece>();

            switch (player)
            {
            case CompPlayer computer:
                boardPieces = computer.CachedPieces;
                break;

            case HumanPlayer human:
                boardPieces = human.CachedPieces;
                break;
            }
            if (bestBoard == null)
            {
                return;
            }
            foreach (Node node in bestBoard.board)
            {
                if (node == null)
                {
                    continue;
                }
                if (node.StoredPiece != null && node.StoredPiece.BelongsTo == player.CurrentTeam.Team)
                {
                    bestBoardPieces.Add(node.StoredPiece);
                }
            }

            //Search through both lists of bestBoardPieces and boardPieces and see if it can find any differences between.
            //If it does, log the differences and use them for later.
            //Currently, this doesnt work. Will have to work on this later.



            foreach (var piece in bestBoardPieces)
            {
                Vector2Int pos = piece.CurrentPosition;

                if (BoardManager.board[pos.x, pos.y] != null)
                {
                    BoardManager.board[pos.x, pos.y].Object.HighlightNode(Color.gray, true);
                }
                if (BoardManager.board[pos.x, pos.y] != null && BoardManager.board[pos.x, pos.y].StoredPiece == null)
                {
                    Debug.Log(BoardManager.board[pos.x, pos.y]);
                    _target = BoardManager.board[pos.x, pos.y];
                }
            }
            foreach (var piece in boardPieces)
            {
                if (piece == null)
                {
                    continue;
                }
                Vector2Int pos = piece.CurrentPosition;
                if (bestBoard[pos.x, pos.y].StoredPiece == null)
                {
                    _selectedPiece = BoardManager.board[pos.x, pos.y].StoredPiece;
                }
            }
        }
Beispiel #7
0
        // GET: List of Players
        public ActionResult LeagueTable(int compID)
        {
            CompMain competition = db.CompMains.Find(compID);

            if (competition == null)
            {
                return(HttpNotFound());
            }
            // Competition Name & CompID
            ViewBag.CompName = competition.CompName;
            ViewBag.CompID   = competition.CompID;

            var pStats = new PlayerStats();
            // Get Player Info for this competition and populate the PlayerView Model
            var getPlayers = (from cp in db.CompPlayers
                              join ur in db.Users on cp.UserID equals ur.UserID
                              join pr in db.Profiles on ur.UserID equals pr.UserID
                              where cp.CompID == compID
                              select new PlayerView
            {
                playerName = ur.UserName,
                compPlayerID = cp.CompPlayerID,
                Photo = pr.Photo
            }).ToList();

            // Loop through each Player and get their Number of Rounds Played, Gross Points, NET Points and average Points per Round
            for (int i = 0; i < getPlayers.Count(); i++)
            {
                getPlayers[i].rndsPlayed      = pStats.NumberRndsPlayed(Convert.ToInt32(compID), getPlayers[i].compPlayerID);
                getPlayers[i].totalPoints     = pStats.TotalNumberPoints(Convert.ToInt32(compID), getPlayers[i].compPlayerID);
                getPlayers[i].totalNETPoints  = pStats.TotalNETPoints(Convert.ToInt32(compID), getPlayers[i].compPlayerID);
                getPlayers[i].avgPointsPerRnd = 0;
                if (getPlayers[i].rndsPlayed > 0)
                {
                    int rnds = getPlayers[i].rndsPlayed;
                    if (getPlayers[i].rndsPlayed > 10)
                    {
                        rnds = 10;
                    }

                    getPlayers[i].avgPointsPerRnd = Math.Round((Double)getPlayers[i].totalNETPoints / rnds, 2);
                }

                // Get current Movement Icon
                getPlayers[i].movementIcon = pStats.GetMovementIcon(getPlayers[i].compPlayerID);
            }
            ;

            // Sort list into Points Descending and apply current Position

            var sortedPlayers = (from sp in getPlayers
                                 orderby sp.avgPointsPerRnd descending, sp.playerName
                                 select sp).ToList();

            for (int i = 0; i < sortedPlayers.Count(); i++)
            {
                sortedPlayers[i].currentPosition = i + 1;
            }

            // See if the weekly league position movement needs to be carried out
            if (DateTime.Now.Date > competition.LeaguePosUpdate)
            {
                // Calculate Week league position movement for each Player
                for (int i = 0; i < sortedPlayers.Count(); i++)
                {
                    int        compPlayerID    = sortedPlayers[i].compPlayerID;
                    CompPlayer cPlayer         = db.CompPlayers.Find(compPlayerID);
                    int        CurrentPos      = sortedPlayers[i].currentPosition;
                    int        SavedWeekPos    = CurrentPos;
                    string     updatedMoveIcon = "";
                    if (cPlayer.WeekPos != null)
                    {
                        SavedWeekPos = Convert.ToInt32(cPlayer.WeekPos);
                    }
                    int posMovement = SavedWeekPos - CurrentPos;
                    sortedPlayers[i].posMove = posMovement;

                    if (posMovement > 0)
                    {
                        sortedPlayers[i].movementIcon = posUp;
                        updatedMoveIcon = posUp;
                    }
                    else if (posMovement < 0)
                    {
                        sortedPlayers[i].movementIcon = posDown;
                        updatedMoveIcon = posDown;
                    }
                    else
                    {
                        sortedPlayers[i].movementIcon = posNomove;
                        updatedMoveIcon = posNomove;
                    }
                    cPlayer.WeekPos         = CurrentPos;
                    cPlayer.CurrentPos      = CurrentPos;
                    cPlayer.MovementIcon    = updatedMoveIcon;
                    db.Entry(cPlayer).State = EntityState.Modified;
                }
                // Update the compMain record with new League Postion Update date + 7 Days from Now

                competition.LeaguePosUpdate = DateTime.Now.AddDays(7);
                db.Entry(competition).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(View(sortedPlayers));
        }
Beispiel #8
0
 private void ComputerShot()
 {
     CompPlayer.Shot(UserShipBoard);
 }
Beispiel #9
0
    static IPlayer CreatePlayer(GameManager.GameMode.Match.Player player, TeamGenerator team)
    {
        IPlayer newPlayer = (player.isComputer) ? CompPlayer.CreatePlayer(player.playerTeam, team) : HumanPlayer.CreatePlayer(player.playerTeam, team);

        return(newPlayer);
    }