/// <summary> /// Obtains the frequency of a board in the history. /// </summary> /// <param name="board">Board to return frequency for.</param> /// <returns>Frequency of board.</returns> public int BoardFrequency(Board board) { int count; m_gameHashHistory.TryGetValue(board.BoardHash(false), out count); return(count); }
/// <summary> /// Adds a position to the opening book. /// </summary> /// <param name="board">Board with position to add.</param> /// <param name="adjustValue">value to adjust the boards value with.</param> public void AddPosition(Board board, int adjustValue) { int currentValue = 0; ZobristHash boardHash = board.BoardHash(true); m_positionTable.TryGetValue(boardHash, out currentValue); m_positionTable[boardHash] = currentValue + adjustValue; }
/// <summary> /// Adds a board to the history. If the board already exists the frequency is increased. /// </summary> /// <param name="board">Board to add.</param> public void AddBoard(Board board) { int count; ZobristHash hash = board.BoardHash(true); m_gameHashHistory.TryGetValue(hash, out count); m_gameHashHistory[hash] = count + 1; }
/// <summary> /// Adds a board to the history. If the board already exists the frequency is increased. /// </summary> /// <param name="board">Board to add.</param> public void AddBoard(Board board) { int count; ZobristHash hash = board.BoardHash(true); m_gameHashHistory.TryGetValue(hash, out count); m_gameHashHistory[hash] = count + 1; }
/// <summary> /// Removes a board from the history. If the frequency for /// the board is larger then one the frequency is decreased. /// </summary> /// <param name="board">Board to remove.</param> public void RemoveBoard(Board board) { int count; ZobristHash hash = board.BoardHash(true); m_gameHashHistory.TryGetValue(hash, out count); if (count > 1) m_gameHashHistory[hash] = count - 1; else m_gameHashHistory.Remove(hash); }
/// <summary> /// Removes a board from the history. If the frequency for /// the board is larger then one the frequency is decreased. /// </summary> /// <param name="board">Board to remove.</param> public void RemoveBoard(Board board) { int count; ZobristHash hash = board.BoardHash(true); m_gameHashHistory.TryGetValue(hash, out count); if (count > 1) { m_gameHashHistory[hash] = count - 1; } else { m_gameHashHistory.Remove(hash); } }
public Move Query(Board board, MoveOrganizer moveOrganizer) { int totalQuaryVal = 0; m_queryMoves.Clear(); foreach (Move move in moveOrganizer) { if (move.Execute(board)) { int currentQueryVal = 0; if (board.State.NonHitAndPawnMovesPlayed < 100 && board.BoardHistoryFrequency() < 3 && m_positionTable.TryGetValue(board.BoardHash(false), out currentQueryVal)) { totalQuaryVal += currentQueryVal; m_queryMoves.Add(new QueryEntry(move, currentQueryVal)); } move.UnExecute(board); } } //select a move using probabilety based on the quary value int selectValueCurrent = 0; int selectValueTarget = (int)Math.Round(m_moveSelector.NextDouble() * totalQuaryVal); for (int i = 0; i < m_queryMoves.Count; ++i) { selectValueCurrent += m_queryMoves[i].QueryScore; if (selectValueCurrent >= selectValueTarget) { OutputWriter.Write("Book moves: " + m_queryMoves.Count + ", Selecting: " + Math.Round((float)m_queryMoves[i].QueryScore / (float)totalQuaryVal, 6)); return m_queryMoves[i].QueryMove; } } return null; }
/// <summary> /// Obtains the frequency of a board in the history. /// </summary> /// <param name="board">Board to return frequency for.</param> /// <returns>Frequency of board.</returns> public int BoardFrequency(Board board) { int count; m_gameHashHistory.TryGetValue(board.BoardHash(false), out count); return count; }