示例#1
0
        /// <summary>
        /// Check if it's possible to certainly (almost) call given information about team
        /// </summary>
        /// <returns>Returns SuitCall object</returns>
        private SuitCall CheckTeammateSuitCalls()
        {
            var sc = new SuitCall();

            for (var i = 0; i < HalfSuits.Keys.Count; i++)
            {
                var mustHaveOnTeam = 0;
                for (var j = 0; j < HalfSuits[HalfSuits.Keys.ToArray()[i]].Length; j++)
                {
                    for (var k = 0; k < 6; k++)
                    {
                        if (PlayerTeams[Players[k]] == PlayerTeams["santiago"])
                        {
                            if (Math.Abs(cardProbability[k][CardIndex[HalfSuits[HalfSuits.Keys.ToArray()[i]][j]]] - 1) < 0.01)
                            {
                                mustHaveOnTeam++;
                            }
                        }
                    }
                }

                if (mustHaveOnTeam == 6)
                {
                    // they have all of a halfsuit
                    sc.Team         = PlayerTeams["santiago"];
                    sc.HalfSuitName = HalfSuits.Keys.ToArray()[i];
                    sc.SenderName   = "santiago";

                    return(sc);
                }
            }

            return(null);
        }
示例#2
0
        public void ProcessMove(SuitCall sc)
        {
            moveList.Add(sc);
            if (sc.Result == CallResult.Hit)
            {
                if (sc.Team == "Red")
                {
                    RedTeamScore++;
                }
                else
                {
                    BlueTeamScore++;
                }
            }
            else
            {
                if (sc.Team == "Red")
                {
                    BlueTeamScore++;
                }
                else
                {
                    RedTeamScore++;
                }
            }

            if (RedTeamScore + BlueTeamScore >= 9)
            {
                GameOver = false; // check if the sum of the scores is 9 (call halfsuits have been called)
            }
        }
示例#3
0
        public void ExportAFN(string gameName)
        {
            string fileString = "";

            for (int i = 0; i < moveList.Count; i++)
            {
                string data = "";
                if (moveList[i].GetType() == typeof(SuitCall))
                {
                    SuitCall c = (SuitCall)moveList[i];
                    data += c.SenderName + ";" + c.Team + ";" + c.HalfSuitName + ";";
                    if (c.Result == CallResult.Hit)
                    {
                        data += "hit";
                    }
                    else if (c.Result == CallResult.Miss)
                    {
                        data += "miss";
                    }
                    else
                    {
                        data += "unknown";
                    }

                    fileString += data + Environment.NewLine;
                }
                else if (moveList[i].GetType() == typeof(CardCall))
                {
                    CardCall c = (CardCall)moveList[i];
                    data += c.SenderName + ";" + c.TargetName + ";" + c.CardRequested + ";";
                    if (c.Result == CallResult.Hit)
                    {
                        data += "hit";
                    }
                    else if (c.Result == CallResult.Miss)
                    {
                        data += "miss";
                    }
                    else
                    {
                        data += "unknown";
                    }

                    fileString += data + Environment.NewLine;
                }
            }

            string path = gameName + ".afn";

            if (!File.Exists(path))
            {
                File.Create(path);
            }

            File.WriteAllText(path, fileString);
        }
示例#4
0
        /// <summary>
        /// Process the suitcall by removing all information about those halfsuits
        /// </summary>
        /// <param name="sc">SuitCall made</param>
        public void ProcessMove(SuitCall sc)
        {
            var halfSuitCalled = HalfSuits[sc.HalfSuitName]; // get the names of the card called

            foreach (string card in halfSuitCalled)
            {
                hand.Remove(CardIndex[card]);
            }

            foreach (string card in halfSuitCalled)
            {
                for (var j = 0; j < 6; j++)
                {
                    haveHalfSuit[j][HalfSuits.Keys.ToList().IndexOf(sc.HalfSuitName)] = 0;
                    cardProbability[j][CardIndex[card]] = 0.0;
                }
            }

            int cardsAccounted = 0;

            while (cardsAccounted < 6)
            {
                // TODO: Maybe keep track of which cards?
                Console.WriteLine("Who had how many cards?");
                var userInput = Console.ReadLine()?.Split(" ");
                if (userInput != null && !Players.Contains(userInput[0]))
                {
                    Utility.Error("Player not found! Please enter a valid player!");
                    continue;
                }

                if (userInput != null)
                {
                    handNumbers[Players.IndexOf(userInput[0])] -= int.Parse(userInput[1]);
                    cardsAccounted += int.Parse(userInput[1]);
                }
            }
        }
示例#5
0
        // ReSharper disable once UnusedParameter.Local
        private static void Main(string[] args)
        {
            #region Initalize
            // Initalize CardIndex and NumberCard
            CardNames = File.ReadAllLines("CardAssignments.txt");
            for (var i = 0; i < CardNames.Length; i++)
            {
                CardIndex.Add(CardNames[i], i); // CardIndex[cardName] = cardNumericalValue
                NumberCard.Add(i, CardNames[i]);
            }

            // Initalize Halfsuits
            var halfSuitNames = File.ReadAllLines("HalfSuitNames.txt");

            var tempHalfSuits = File.ReadAllLines("HalfSuits.txt");
            for (var i = 0; i < tempHalfSuits.Length; i++)
            {
                HalfSuits.Add(halfSuitNames[i], tempHalfSuits[i].Split(','));
            }

            Console.ForegroundColor = ConsoleColor.White;
            var ai = new AI();

            Players.Add("santiago");
            PlayerTeams.Add("santiago", "Blue");

            for (var i = 2; i <= 6; i++)
            {
                Console.WriteLine($"What is player {i}'s name?");
                string nameInput = Console.ReadLine()?.ToLower();
                while (Players.Contains(nameInput))
                {
                    Console.WriteLine("That name is already taken!");
                    nameInput = Console.ReadLine()?.ToLower();
                }
                Players.Add(nameInput);
                if (Players.Count % 2 == 0)
                {
                    PlayerTeams.Add(nameInput, "Red");
                }
                else
                {
                    PlayerTeams.Add(nameInput, "Blue");
                }
            } // initalize the Player (names) list
            #endregion

            // Start game
            var game = new Game();

            Console.WriteLine("Who's turn it is?");

            string inpPlayerTurn = Console.ReadLine()?.ToLower();
            while (!Players.Contains(inpPlayerTurn))
            {
                Utility.Alert($"{inpPlayerTurn} is not a player! Please enter a valid player name.");
                inpPlayerTurn = Console.ReadLine();
            }

            game.PlayerTurn = inpPlayerTurn;

            while (!game.GameOver)
            {
                if (game.PlayerTurn != "santiago")
                {
                    // Take in move made
                    Console.WriteLine($"{game.PlayerTurn}'s turn! What move did they make?");
                    var moveData = Console.ReadLine()?.Split(" ");

                    if (moveData?[0] == "call") // ["call", HalfSuit, Result]
                    {
                        // Halfsuit Called
                        if (!HalfSuits.ContainsKey(moveData?[1]))
                        {
                            Utility.Error("Halfsuit not recognized!");
                            continue;
                        }
                        if (moveData?[2] != "hit" && moveData?[2] != "miss")
                        {
                            Utility.Error("Result not recognized!");
                            continue;
                        }

                        var res = moveData[2] == "hit" ? CallResult.Hit : CallResult.Miss;
                        var sc  = new SuitCall(moveData[1].ToUpper(), PlayerTeams[game.PlayerTurn], game.PlayerTurn, res);
                        game.ProcessMove(sc);
                        ai.ProcessMove(sc);
                    }
                    else if (Players.Contains(moveData?[0])) // [TargetName, CardName, Result]
                    {
                        // Card Called
                        if (!CardIndex.ContainsKey(moveData?[1]))
                        {
                            Utility.Error("Card not recognized!");
                            continue;
                        }
                        if (moveData?[2] != "hit" && moveData?[2] != "miss")
                        {
                            Utility.Error("Result not recognized!");
                            continue;
                        }

                        var res = moveData?[2] == "hit" ? CallResult.Hit : CallResult.Miss;
                        var cc  = new CardCall(moveData?[0].ToLower(), game.PlayerTurn, moveData?[1], res);
                        game.ProcessMove(cc);
                        ai.ProcessMove(cc);
                    }
                    else
                    {
                        Utility.Error("Invalid command! Calltype not recognized!");
                        game.ExportAFN("testGame");
                    }
                }
                else
                {
                    // Make a move
                    // ReSharper disable once InconsistentNaming
                    var AIMove = ai.MakeMove(game);
                    Utility.PrintCardCall(AIMove);
                    Console.WriteLine("Result of Santiago's move? Hit/Miss");
                    string resString = Console.ReadLine()?.ToLower();

                    AIMove.Result = resString == "hit" ? CallResult.Hit : CallResult.Miss;

                    ai.ProcessMove(AIMove);
                    game.ProcessMove(AIMove);
                }
            }
        }