using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using HoldemHand;
public class GameManager : MonoBehaviour
{
public DeckScript deckScript;
private CardScript[] allCards = new CardScript[7];
private CardScript[] boardCards = new CardScript[5];
private List<Hand> equalHands = new List<Hand>();
private string boardString = "";
private List<Hand> handList = new List<Hand>();
[SerializeField]
private List<PlayerScript> playerScripts = new List<PlayerScript>();
private Dictionary<PlayerScript, Hand> keyValuePairs = new Dictionary<PlayerScript, Hand>();
public void DealClicked()
{
ResetGame();
for (int i = 0; i < playerScripts.Count ; i++)
playerScripts[i].StartHand();// player gets cards
deckScript.DealCommunityCards();
}
public void Check()
{
for (int i = 0; i < deckScript.communityCards.Length; i++)
{
boardCards[i] = deckScript.communityCards[i];
boardString += boardCards[i].Formatting();
if (!(i == allCards.Length)) boardString += " ";
}
//Hand h1 = new Hand(player1Script.GenerateFormatting(), boardString);
//Hand h2 = new Hand(player2Script.GenerateFormatting(), boardString);
StoreHandValues();
CompareHandValues();
/*
for(int i = 0; i < boardCards.Length; i++)
{
boardString += boardCards[i].Formatting();
if (!(i == allCards.Length)) boardString += " ";
}
*/
//Debug.Log("h1: " + h1.HandTypeValue);
//Debug.Log("h2: " + h2.HandTypeValue);
//if (h1 > h2) Debug.Log("h1 > h2");
//else Debug.Log("h2 > h1");
}
private void StoreHandValues()
{
keyValuePairs.Clear();
for (int i = 0; i < playerScripts.Count; i++)
{
handList.Add(new Hand(playerScripts[i].GenerateFormatting(), boardString));
keyValuePairs.Add(playerScripts[i], handList[i]);
}
}
private Hand CompareHandValues()
{
Hand largestHand = keyValuePairs.Values.Max();
var repeats = keyValuePairs.GroupBy(x => largestHand).Where(x => x.Count() > 1);
if (repeats != null)
{
Debug.Log("pot is shared");
}
else
{
Debug.Log("as usual");
}
return largestHand;
}
private void ResetGame()
{
deckScript.Shuffle();
foreach (PlayerScript playerScript in playerScripts)
playerScript.ResetHand();
deckScript.ResetDeck();
}
}
Hi all, this is my GameManager script. It has no errors initially, but when I go into runtime and call the Check() function, there is an argument null exception that occurs at line 69. May I know what is causing the issue?
