Beginner problems....

mrlowbot

Member
Joined
Apr 30, 2021
Messages
11
Programming Experience
Beginner
Hey.

I need some help when it comes to my code, its not meant to have a "main" method.
It is basically a chess program that takes values and compares them, checks players and how much they score.

This is what i need to do :

We organize a chess tournament in the local club. The members are divided into
"regular" players and grandmasters.
Write a class ChessTournament (line 33) that has:
Two private lists containing each class above (row 8, row 20)
Stuck here == > A suitable constructor
A Clear () method that removes all elements in both lists
A NumberPlayer () method that returns the number of players in the tournament
Two methods for adding a new player to the correct list
Stuck here == > A Maximum Score () method that returns the highest score any player has.
If all players have zero points, return zero instead.

(b) It's a bit clumsy to have two separate lists just because we have two different player classes.
Redesign the player classes, possibly with a third class or interface, to make it easier the handling. Write an updated version of ChessTournament that uses this.'

This is how far i've gotten:

Chess, NUnit testing:
 class Program
    {
        class NormalPlayer
        {
            public string Name;
            public int Score;
            public int Handicap;
            public NormalPlayer(string n, int h)
            {
                Name = n;
                Score = 0;
                Handicap = h;
            }
        }
        class Grandmaster
        {
            public string Name;
            public int Score;
            public string Country;
            public Grandmaster(string n, string c)
            {
                Name = n;
                Score = 0;
                Country = c;
            }
        }

        class ChessTournament
        {
            /// <summary>
            /// List for "NP = Normal players" and "GM = Grandmaster players".
            /// </summary>
           public List<NormalPlayer> NP = new List<NormalPlayer>();
           public List<Grandmaster> GM = new List<Grandmaster>();

            /// <summary>
            /// Add normal players to the list.
            /// </summary>
            /// <param name="normalPlayer"></param>
            public void AddNP(NormalPlayer normalPlayer)
            {
                NP.Add(normalPlayer);
            }
            /// <summary>
            /// Add grand master players to the list.
            /// </summary>
            /// <param name="grandmaster"></param>
            public void AddGM(Grandmaster grandmaster)
            {
                GM.Add(grandmaster);
            }

            /// <summary>
            /// Stuck here!
            /// </summary>
            /// <param name="score"></param>
            /// <returns></returns>
            public string HighestScore(int score)
            {
              
            }
            /// <summary>
            /// Write the total amount of players in the game.
            /// </summary>
            /// <param name="players"></param>
            /// <returns></returns>
            public int TotalPlayers(int players)
            {
                players = GM.Count + NP.Count;
                return players;
            }

            public void Clean()
            {
                NP.Clear();
                GM.Clear();
            }
        }

How should i proceed to make this all work?

Regards, :)
 
Last edited:

mrlowbot

Member
Joined
Apr 30, 2021
Messages
11
Programming Experience
Beginner
So now i want to create another class with some better values that i later want to test aswell.

This is how far I've gotten, quesiton: Should i use get/set instead of "this.Rank = rank" etc?

Updated:
 class UpdatedChess
    {
        class Player
        {
            public string Name;
            public int Score;
            public int Rating;
            public string Rank;
            public Player(string name, int score, int rating, string rank)
            {
                this.Rating = rating;
                this.Score = score;
                this.Name = name;
                this.Rank = rank;

            }
        }


        class UpdatedChessTournament
        {
            public List<Player> Players = new List<Player>();
            public void AddPlayer(Player P)
            {
                Players.Add(P);
            }

            public int TotalPlayers()
            {
                int player;
                player = Players.Count;
                return player;
            }

            public void Ranking(Player P)
            {
                foreach(var item in Players)
                {
                    if(P.Score > 500)
                    {
                    P.Rank = "Bronze";
                    }
                    if(P.Score > 1000)
                    {
                        P.Rank = "Silver";
                    }
                    if(P.Score > 2999)
                    {
                        P.Rank = "GrandMaster";
                    }
                }
            }
        }
    }
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,364
Location
Chesapeake, VA
Programming Experience
10+
You have to right click on the project and select Run tests... :)
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,364
Location
Chesapeake, VA
Programming Experience
10+
Top Bottom