private bool EndTurn(GameLogEntry logEntry, int column, bool pause = true, bool drawBoard = true) { if (column == -1) { log.Winner = 0; return(false); } if (rules.IsValidMove(column, board)) { board.DropChecker(column, PlayerTurn); logEntry.ColumnPlayed = column; log.Add(logEntry); var winningGroups = rules.PlayerWins(PlayerTurn, board); if (winningGroups.Any()) { log.Winner = PlayerTurn; return(false); } } else { return(true); } PlayerTurn = PlayerTurn == 1 ? 2 : 1; return(true); }
public bool PlayAutomated(bool pauseOnTurn) { AutoTurns++; var random = new Random(); var randomChance = random.Next(10); GameLogEntry logEntry = NewLogEntry(); int column = -1; var boardSearch = new BoardSearch(numberToWin); var legalMoves = boardSearch.FindAllLegalMoves(board); if (legalMoves.Count == 0) { return(EndTurn(logEntry, -1, pauseOnTurn)); } if (boardSearch.IsBoardEmpty(board)) { //Console.WriteLine("Random move. "); column = random.Next(6); } else { var strategy = PlayerTurn == 1 ? strategy1 : strategy2; var depth = PlayerTurn == 1 ? Player1SearchDepth : GetSearchDepth(AutoTurns); column = strategy.Run(board, numberToWin, PlayerTurn, depth); } return(EndTurn(logEntry, column, pauseOnTurn, true)); }
private GameLogEntry NewLogEntry() { var logEntry = new GameLogEntry(); logEntry.BoardBeforeMove = (int[, ])board.Matrix.Clone(); logEntry.PlayerNumber = PlayerTurn; return(logEntry); }
public void LogEntry(GameLogEntry logEntry) { if (!GameLogManager.Instance.AuthentificatedClients.Any(s => s.Equals(CurrentClient.ClientId)) || logEntry == null) { return; } logEntry.Timestamp = DateTime.UtcNow; GameLogManager.Instance.GameLogs.Add(logEntry); GameLogManager.Instance.AllGameLogs.Add(logEntry); }
public void Add(string description, string eventName, object details) { var newEntry = new GameLogEntry { Description = description, User = _playerContext, Details = details }; //string detailsJson = new JavaScriptSerializer().Serialize(newEntry.Details); string insertSql = $"INSERT INTO [GameLog] ([Description], [User], [TimeStamp], [Event], [Details]) VALUES"; insertSql += $"('{newEntry.Description}', '{newEntry.User}', getdate(), '{newEntry.EventName}', NULL)"; _dataContext.ExecuteCommand(insertSql); }
private void AddNewGameLogEntry(GameLogEntry entry) { data.GameLog.Add(entry); SetGameLogEntryRows(); }
public void LogEntry(GameLogEntry logEntry) => _client.ServiceProxy.LogEntry(logEntry);
public void Add(GameLogEntry entry) { Log.Add(entry); }