int GameNNTrainToWin(NeuralNetwork neuralNetwork, List <Card> deck) { List <Player> Players = new List <Player>(); Players.Add(new Player(1, true)); Players.Add(new Player(2, false)); Players[0].Leading = true; //Set Player One to lead trick //Apply Neural Network Weights to Deck NNDecideCard.ApplyWeightsToCards(neuralNetwork, deck); Decision.SetTrumps(deck, 3); //Set Spades as Trump Deal.DealToPlayersNN(Players, deck); Decision.DecideBids(Players); //Train To Win Set Bid to 10 Players[0].Bid = 10; //Record Player 1 Hand HandRecord handRecord = Record.RecordHandInit(Players.FirstOrDefault(x => x.ID == 1)); //State that player 1 should use Neural Network Players.FirstOrDefault(x => x.ID == 1).UseNN = true; //Write out bids //WriteBids(Players); //Write out Hands //WriteHands(Players); for (int i = 1; i < 11; i++) { //Console.WriteLine("Game " + i); //Set NN player to always lead for better training Players.FirstOrDefault(p => p.UseNN == true).Leading = true; Decision.DecideCardToPlayNN(Players, neuralNetwork); Decision.PlayCardNN(Players, false); } return(Players.FirstOrDefault(x => x.ID == 1).Wins); }
public static void WriteHandResult(HandRecord handRecord) { var csv = new StringBuilder(); var newLine = string.Format("{0},{1},{2},{3},{4}", handRecord.Bid, handRecord.NumberOfTrumpCards, handRecord.TotalValue, handRecord.NumberOfAces, handRecord.NumberOfTwos); csv.AppendLine(newLine); //after your loop if (handRecord.GameWon == 1) { File.AppendAllText("Z:\\Repos\\ContractWhist\\ContractWhist\\Writer\\HandRecord.csv", csv.ToString()); } }
public static void WriteHandResult(HandRecord handRecord) { var csv = new StringBuilder(); var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", handRecord.Bid, handRecord.NumberOfTrumpCards, handRecord.ValueOfTrumpCards, handRecord.ValueOfNonTrumpCards, handRecord.NumberOfAces, handRecord.NumberOfTwos, Math.Round(handRecord.StdDevOfNonTrump, 3).ToString(), handRecord.Mean, handRecord.MeanNonTrump, handRecord.MeanTrump, handRecord.CardsInHand); csv.AppendLine(newLine); //after your loop if (handRecord.GameWon == 1) { File.AppendAllText("Z:\\Repos\\ContractWhist\\ContractWhist\\Writer\\HandRecord.csv", csv.ToString()); } }
public static HandRecord RecordHandInit(Player player) { HandRecord hr = new HandRecord(); hr.Bid = player.Bid; hr.CardsInHand = player.HandSeperatedString(); hr.TotalValue = player.SumValue(); hr.NumberOfTrumpCards = player.NumberOfTrumpCards(); hr.NumberOfAces = player.NumberOfValueCard(14); hr.NumberOfTwos = player.NumberOfValueCard(2); hr.GameWon = 0; return(hr); }
static void Game() { List <Player> Players = new List <Player>(); Players.Add(new Player(1, true)); Players.Add(new Player(2, false)); Players[0].Leading = true; //Set Player One to lead trick List <Card> deck = Deal.CreateDeck(); Decision.SetTrumps(deck, 3); //Set Spades as Trump Deal.DealToPlayers(Players, deck); Decision.DecideBids(Players); //Record Player 1 Hand HandRecord handRecord = Record.RecordHandInit(Players.FirstOrDefault(x => x.ID == 1)); //Write out bids foreach (Player player in Players) { Console.WriteLine("Player: " + player.ID + " Bid: " + player.Bid); } //Write out Hands foreach (Player player in Players) { Console.WriteLine("Player " + player.ID + " Hand:"); List <Card> OrderedHand = player.Hand.OrderBy(x => x.Value).OrderBy(x => x.suit.ID).ToList(); foreach (Card card in OrderedHand) { Console.WriteLine("Card ID: " + card.ID + " Card Value: " + card.ValueName + " of " + card.suit.SuitName); } Console.WriteLine(""); } for (int i = 1; i < 11; i++) { Console.WriteLine("Game " + i); Decision.DecideCardToPlay(Players); Decision.PlayCard(Players); } //Work out wins foreach (Player player in Players) { Console.WriteLine("Player Wins: " + player.Wins + " Bid: " + player.Bid); } //Record if PlayerOne was successful if (Players.FirstOrDefault(x => x.ID == 1).Wins == Players.FirstOrDefault(x => x.ID == 1).Bid) { handRecord.GameWon = 1; } CSVWriter.WriteHandResult(handRecord); }
public static HandRecord RecordHandInit(Player player) { HandRecord hr = new HandRecord(); hr.Bid = player.Bid; hr.CardsInHand = player.HandSeperatedString(); hr.TotalValue = player.SumValue(); hr.Mean = player.Mean(); hr.NumberOfTrumpCards = player.NumberOfTrumpCards(); hr.NumberOfAces = player.NumberOfValueCard(14); hr.NumberOfTwos = player.NumberOfValueCard(2); hr.ValueOfTrumpCards = player.SumValueConsideringTrump(true); hr.ValueOfNonTrumpCards = player.SumValueConsideringTrump(false); hr.StdDevOfNonTrump = player.StdDevConsideringTrump(false); hr.MeanNonTrump = player.MeanConsideringTrump(false); hr.MeanTrump = player.MeanConsideringTrump(true); hr.GameWon = 0; return(hr); }
int Game() { List <Player> Players = new List <Player>(); Players.Add(new Player(1, true)); Players.Add(new Player(2, false)); Players[0].Leading = true; //Set Player One to lead trick List <Card> deck = Deal.CreateDeck(); Decision.SetTrumps(deck, 3); //Set Spades as Trump Deal.DealToPlayers(Players, deck); Decision.DecideBids(Players); //Record Player 1 Hand HandRecord handRecord = Record.RecordHandInit(Players.FirstOrDefault(x => x.ID == 1)); //Write out bids WriteBids(Players); //Write out Hands WriteHands(Players); for (int i = 1; i < 11; i++) { Console.WriteLine("Game " + i); Decision.DecideCardToPlay(Players); Decision.PlayCard(Players, true); } //Work out wins foreach (Player player in Players) { Console.WriteLine("Player Wins: " + player.Wins + " Bid: " + player.Bid); } //Record if PlayerOne was successful if (Players.FirstOrDefault(x => x.ID == 1).Wins == Players.FirstOrDefault(x => x.ID == 1).Bid) { handRecord.GameWon = 1; } CSVWriter.WriteHandResult(handRecord); return(handRecord.GameWon); }