public override void GradeBoards( MoveRepresentationList list, BoardRepresentation initialBoard ) { int race = 1; bool opponentFound = false; for ( int i = 0; i < initialBoard.SquareCount() && race == 1; i++ ) { if ( !opponentFound && initialBoard.GetPiecesAt( i ) < 0 ) opponentFound = true; if ( opponentFound && initialBoard.GetPiecesAt( i ) > 0 ) race = 0; } for ( int i = 0; i < list.Count(); i++ ) { int[] pubevalBoard = new int[28]; MoveRepresentation currentBoard = list.GetMoveRepresentation( i ); for ( int j = 0; j < currentBoard.SquareCount(); j++ ) pubevalBoard[j] = currentBoard.GetPiecesAt( j ); pubevalBoard[26] = currentBoard.BearOffCountCurrent(); pubevalBoard[27] = currentBoard.BearOffCountOpponent(); double s = PubevalGrade( race, pubevalBoard ); list.GetMoveRepresentation( i ).AddScore( s ); } }
public bool EndTurn() { FindWinner(); if (m_Winner != BgPlayer.None) { BoardRepresentation finalBoard = new BoardRepresentation(this); if (m_History.Count() > 0 && !m_History.PeekLast().PatternMatches(finalBoard)) { m_History.Add(finalBoard); m_History.Winner = m_Winner; m_History.WinType = VictoryType(); } return(false); } if (!IsMovesUsed()) { if (DoesValidMoveExist()) { return(false); } } m_History.Add(new BoardRepresentation(this)); m_UndoStack.Clear(); m_CurrentPlayer = CurrentOpponentPlayer; SetCorrectlySwitchedBoard(); RollDices(); m_MaxMovesPossible = MaxMovesPossible(0); return(true); }
public override void GradeBoards( MoveRepresentationList list, BoardRepresentation initialBoard ) { for ( int i = 0; i < list.Count(); i++ ) { double s = m_FuzzyController.ObtainBoardStrength( list.GetMoveRepresentation( i ) ); list.GetMoveRepresentation( i ).AddScore( s ); } }
public override void GradeBoards( MoveRepresentationList list, BoardRepresentation initialBoard ) { for ( int i = 0; i < list.Count(); i++ ) { double s = m_Random.NextDouble() - m_Random.NextDouble(); list.GetMoveRepresentation( i ).AddScore( s ); } }
public override LinguisticInputValue CreateLinguisticInputValue( BoardRepresentation board ) { LinguisticInputValue result = new LinguisticInputValue( GetName(), 0 ); for ( int i = 1; i < 26; i++ ) if ( board.GetPiecesAt( i ) > 0 ) result.CrispValue = i; return result; }
public override bool AcceptDouble( BoardRepresentation board ) { float[] output = Grade( board ); float totalWinSum = output[0] + output[1] + output[2]; if ( totalWinSum < 0.25f ) return false; return true; }
public override void GradeBoards( MoveRepresentationList list, BoardRepresentation initialBoard ) { for ( int i = 0; i < list.Count(); i++ ) { float[] output = Grade( list.GetMoveRepresentation( i ) ); double s = output[0] + (2 * output[1]) + (3 * output[2]) - (2 * output[3]) - (3 * output[4]); list.GetMoveRepresentation( i ).AddScore( s ); } }
public override bool AcceptDouble( BoardRepresentation board ) { bool race = Race( board ); Grade( board, race, m_Output ); float totalWinSum = m_Output[0] + m_Output[1] + m_Output[2]; if ( totalWinSum < 0.25f ) return false; return true; }
public override bool Double( BoardRepresentation flippedBoard ) { float[] output = Grade( flippedBoard ); float totalWinSum = output[0] + output[1] + output[2]; float gammonWinSum = output[1] + output[2]; if ( totalWinSum >= 0.66f && gammonWinSum < 0.5f ) return true; return false; }
public void Callibrate( BoardRepresentation[] winnerBoards, BoardRepresentation[] loserBoards ) { AvgLinguisticInputResult[] avgWinnerInput = GetAverageInput( winnerBoards ); for ( int i = 0; i < avgWinnerInput.Length; i++ ) { MfInterface[] memberFunctions = m_Controller.GetMembershipFunctions( avgWinnerInput[i].VariableName ); for ( int j = 0; j < memberFunctions.Length; j++ ) memberFunctions[j].AdjustToTargetPoint( avgWinnerInput[i].CrispValue, 0.05 ); } }
public bool PatternMatches( BoardRepresentation repr ) { int[] tmp = repr.m_BoardPattern; if ( tmp.Length != m_BoardPattern.Length ) return false; for ( int i = 0; i < m_BoardPattern.Length; i++ ) if ( m_BoardPattern[i] != tmp[i] ) return false; return true; }
public bool AcceptDouble() { if ( IsAgentPlaying( m_BgGame.CurrentPlayer ) ) { BoardRepresentation board = new BoardRepresentation( m_BgGame ); int evaluator = m_GUI.SelectedEvaluator(); if ( evaluator >= 0 ) return m_Plugins[evaluator].AcceptDouble( board ); } return true; }
public override bool Double( BoardRepresentation flippedBoard ) { bool race = Race( flippedBoard ); Grade( flippedBoard, race, m_Output ); float totalWinSum = m_Output[0] + m_Output[1] + m_Output[2]; float gammonWinSum = m_Output[1] + m_Output[2]; if ( totalWinSum >= 0.66f && gammonWinSum < 0.5f ) return true; return false; }
public BoardRepresentation Remove(int idx) { if (m_List.Count > idx) { BoardRepresentation result = Peek(idx); m_List.RemoveAt(idx); return(result); } else { return(null); } }
public override void Learn( GameHistory history ) { m_Trained = true; BoardRepresentation[] looserBoards = new BoardRepresentation[history.Count() / 2]; int looserIdx = looserBoards.Length; for ( int i = history.Count()-2; i >= 0; i -= 2 ) looserBoards[--looserIdx] = history.Peek( i ); BoardRepresentation[] winnerBoards = new BoardRepresentation[history.Count() - looserBoards.Length]; int winnerIdx = winnerBoards.Length; for ( int i = history.Count()-1; i >= 0; i -= 2 ) winnerBoards[--winnerIdx] = history.Peek( i ); m_FuncCallibrator.Callibrate( winnerBoards, looserBoards ); }
public override LinguisticInputValue CreateLinguisticInputValue( BoardRepresentation board ) { bool opponentFound = false; LinguisticInputValue result = new LinguisticInputValue( GetName(), 0 ); for ( int i = 0; i < 26; i++ ) { if ( board.GetPiecesAt( i ) < 0 ) { opponentFound = true; } if ( board.GetPiecesAt( i ) > 0 && opponentFound ) { result.CrispValue = 1; break; } } return result; }
public bool PatternMatches(BoardRepresentation repr) { int[] tmp = repr.m_BoardPattern; if (tmp.Length != m_BoardPattern.Length) { return(false); } for (int i = 0; i < m_BoardPattern.Length; i++) { if (m_BoardPattern[i] != tmp[i]) { return(false); } } return(true); }
private AvgLinguisticInputResult[] GetAverageInput( BoardRepresentation[] boards ) { AvgLinguisticInputResult[] result = new AvgLinguisticInputResult[m_Controller.PreProcessorCount()]; LinguisticInputValue[] inValues = m_Controller.ObtainCrispInput( boards[0] ); for ( int i = 0; i < inValues.Length; i++ ) result[i] = new AvgLinguisticInputResult( inValues[i].VariableName, ( double )inValues[i].CrispValue ); for ( int i = 1; i < boards.Length; i++ ) { inValues = m_Controller.ObtainCrispInput( boards[i] ); for ( int j = 0; j < inValues.Length; j++ ) result[j].CrispValue += ( double )inValues[j].CrispValue; } for ( int i = 0; i < result.Length; i++ ) result[i].CrispValue = result[i].CrispValue / ( double )boards.Length; return result; }
private void Train( BoardRepresentation currentBoard, float[] target ) { int race = Race( currentBoard ); float[] input = BoardToNetworkInput( currentBoard ); m_NeuralNetworks[race].Train( input, target, 0.00001f, 0.2f ); }
private int Race( BoardRepresentation currentBoard ) { int race = 1; bool opponentFound = false; for ( int j = 0; j < currentBoard.SquareCount() && race == 1; j++ ) { if ( !opponentFound && currentBoard.GetPiecesAt( j ) < 0 ) opponentFound = true; if ( opponentFound && currentBoard.GetPiecesAt( j ) > 0 ) race = 0; } return race; }
private float[] Grade( BoardRepresentation currentBoard ) { int race = Race( currentBoard ); float[] input = BoardToNetworkInput( currentBoard ); float[] output = new float[5]; m_NeuralNetworks[race].Run( input, output ); return output; }
private float[] BoardToNetworkInput( BoardRepresentation currentBoard ) { int Idx = 0; float[] board = new float[196]; for ( int i = 1; i < 25; i++ ) { int pieces = currentBoard.GetPiecesAt( i ); if ( pieces == 0 ) { board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces == 1 ) { board[Idx++] = 1; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces == 2 ) { board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces == 3 ) { board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces > 3 ) { board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = ( pieces - 3 ) / 2.0f; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces == -1 ) { board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 1; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces == -2 ) { board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 0; board[Idx++] = 0; } else if ( pieces == -3 ) { board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 0; } else if ( pieces < -3 ) { board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 0; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = 1; board[Idx++] = ( -pieces - 3 ) / 2.0f;; } } board[Idx++] = currentBoard.GetPiecesAt( 25 ) / 2.0f; board[Idx++] = -currentBoard.GetPiecesAt( 0 ) / 2.0f; board[Idx++] = currentBoard.BearOffCountCurrent() / 15.0f; board[Idx++] = -currentBoard.BearOffCountOpponent() / 15.0f; return board; }
public override LinguisticInputValue CreateLinguisticInputValue( BoardRepresentation board ) { LinguisticInputValue result = new LinguisticInputValue( GetName(), -board.GetPiecesAt( 0 ) ); return result; }
public override void Learn( GameHistory history ) { BoardRepresentation[] looserBoards = new BoardRepresentation[history.Count() / 2]; int looserIdx = looserBoards.Length; for ( int i = history.Count()-2; i >= 0; i -= 2 ) looserBoards[--looserIdx] = history.Peek( i ); BoardRepresentation[] winnerBoards = new BoardRepresentation[history.Count() - looserBoards.Length]; int winnerIdx = winnerBoards.Length; for ( int i = history.Count()-1; i >= 0; i -= 2 ) winnerBoards[--winnerIdx] = history.Peek( i ); int wIdx = winnerBoards.Length - 1; int lIdx = looserBoards.Length - 1; float[] wTarget = Grade( winnerBoards[wIdx] );; float[] lTarget = Grade( looserBoards[lIdx] ); if ( history.WinType == 1 ) { wTarget[0] = wTarget[0] + ( 0.1f * ( 1.0f - wTarget[0] ) ); wTarget[1] = wTarget[1] + ( 0.1f * ( 0.0f - wTarget[1] ) ); wTarget[2] = wTarget[2] + ( 0.1f * ( 0.0f - wTarget[2] ) ); wTarget[3] = wTarget[3] + ( 0.1f * ( 0.0f - wTarget[3] ) ); wTarget[4] = wTarget[4] + ( 0.1f * ( 0.0f - wTarget[4] ) ); lTarget[0] = lTarget[0] + ( 0.1f * ( 0.0f - lTarget[0] ) ); lTarget[1] = lTarget[1] + ( 0.1f * ( 0.0f - lTarget[1] ) ); lTarget[2] = lTarget[2] + ( 0.1f * ( 0.0f - lTarget[2] ) ); lTarget[3] = lTarget[3] + ( 0.1f * ( 0.0f - lTarget[3] ) ); lTarget[4] = lTarget[4] + ( 0.1f * ( 0.0f - lTarget[4] ) ); } else if ( history.WinType == 2 ) { wTarget[0] = wTarget[0] + ( 0.1f * ( 0.0f - wTarget[0] ) ); wTarget[1] = wTarget[1] + ( 0.1f * ( 1.0f - wTarget[1] ) ); wTarget[2] = wTarget[2] + ( 0.1f * ( 0.0f - wTarget[2] ) ); wTarget[3] = wTarget[3] + ( 0.1f * ( 0.0f - wTarget[3] ) ); wTarget[4] = wTarget[4] + ( 0.1f * ( 0.0f - wTarget[4] ) ); lTarget[0] = lTarget[0] + ( 0.1f * ( 0.0f - lTarget[0] ) ); lTarget[1] = lTarget[1] + ( 0.1f * ( 0.0f - lTarget[1] ) ); lTarget[2] = lTarget[2] + ( 0.1f * ( 0.0f - lTarget[2] ) ); lTarget[3] = lTarget[3] + ( 0.1f * ( 1.0f - lTarget[3] ) ); lTarget[4] = lTarget[4] + ( 0.1f * ( 0.0f - lTarget[4] ) ); } else if ( history.WinType == 3 ) { wTarget[0] = wTarget[0] + ( 0.1f * ( 0.0f - wTarget[0] ) ); wTarget[1] = wTarget[1] + ( 0.1f * ( 0.0f - wTarget[1] ) ); wTarget[2] = wTarget[2] + ( 0.1f * ( 1.0f - wTarget[2] ) ); wTarget[3] = wTarget[3] + ( 0.1f * ( 0.0f - wTarget[3] ) ); wTarget[4] = wTarget[4] + ( 0.1f * ( 0.0f - wTarget[4] ) ); lTarget[0] = lTarget[0] + ( 0.1f * ( 0.0f - lTarget[0] ) ); lTarget[1] = lTarget[1] + ( 0.1f * ( 0.0f - lTarget[1] ) ); lTarget[2] = lTarget[2] + ( 0.1f * ( 0.0f - lTarget[2] ) ); lTarget[3] = lTarget[3] + ( 0.1f * ( 0.0f - lTarget[3] ) ); lTarget[4] = lTarget[4] + ( 0.1f * ( 1.0f - lTarget[4] ) ); } while ( lIdx >= 0 || wIdx >= 0 ) { if ( wIdx >= 0 ) { Train( winnerBoards[wIdx], wTarget ); if ( wIdx > 0 ) { float[] prevWState = Grade( winnerBoards[wIdx-1] ); wTarget[0] = prevWState[0] + ( 0.1f * ( wTarget[0] - prevWState[0] ) ); wTarget[1] = prevWState[1] + ( 0.1f * ( wTarget[1] - prevWState[1] ) ); wTarget[2] = prevWState[2] + ( 0.1f * ( wTarget[2] - prevWState[2] ) ); wTarget[3] = prevWState[3] + ( 0.1f * ( wTarget[3] - prevWState[3] ) ); wTarget[4] = prevWState[4] + ( 0.1f * ( wTarget[4] - prevWState[4] ) ); } wIdx--; } if ( lIdx >= 0 ) { Train( looserBoards[lIdx], lTarget ); if ( lIdx > 0 ) { float[] prevLState = Grade( looserBoards[lIdx-1] ); lTarget[0] = prevLState[0] + ( 0.1f * ( lTarget[0] - prevLState[0] ) ); lTarget[1] = prevLState[1] + ( 0.1f * ( lTarget[1] - prevLState[1] ) ); lTarget[2] = prevLState[2] + ( 0.1f * ( lTarget[2] - prevLState[2] ) ); lTarget[3] = prevLState[3] + ( 0.1f * ( lTarget[3] - prevLState[3] ) ); lTarget[4] = prevLState[4] + ( 0.1f * ( lTarget[4] - prevLState[4] ) ); } lIdx--; } } m_GamesTrained++; if ( m_GamesTrained % 100 == 0 ) Save( SAVE_FILE ); }
private void SetContactInput( BoardRepresentation board, float[] input ) { for ( int i = 0; i < input.Length; i++ ) input[i] = 0.0f; for ( int i = 0; i < 26; i++ ) { m_OwnBoardView[i] = board.GetPiecesAt( i ); m_OppBoardView[25-i] = -board.GetPiecesAt( i ); } int idx = 0; idx = SetBoard( m_OwnBoardView, input, idx ); idx = SetContactBeardOff( m_OwnBoardView, input, idx ); idx = SetBar( m_OwnBoardView, input, idx ); idx = SetHalfContactInput( m_OwnBoardView, input, idx ); idx = SetHalfContactInput( m_OppBoardView, input, idx ); }
public void CalculateHitProbability( int position, int hitFrom, BoardRepresentation board, bool[,] hittingDices ) { int distance = position - hitFrom; for ( int i = 1; i <= 6; i++ ) { for ( int j = 1; j <= 6; j++ ) { if ( distance == i || distance == j ) { if ( board.GetPiecesAt( 0 ) == 0 ) { hittingDices[i-1,j-1] = true; } else if ( board.GetPiecesAt( 0 ) < 0 && hitFrom == 0 ) { hittingDices[i-1,j-1] = true; } else if ( board.GetPiecesAt( 0 ) == -1 && hitFrom != 0 ) { if ( distance == i && board.GetPiecesAt( j ) < 2 ) { hittingDices[i-1,j-1] = true; } else if ( distance == j && board.GetPiecesAt( i ) < 2 ) { hittingDices[i-1,j-1] = true; } } else if ( i == j && ( board.GetPiecesAt( 0 ) == -1 || board.GetPiecesAt( 0 ) == -2 || board.GetPiecesAt( 0 ) == -3 ) && board.GetPiecesAt( i ) < 2 ) { hittingDices[i-1,j-1] = true; } } else if ( distance == i + j ) { if ( board.GetPiecesAt( 0 ) == 0 ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 || board.GetPiecesAt( hitFrom + j ) < 2 ) hittingDices[i-1,j-1] = true; } else if ( board.GetPiecesAt( 0 ) == -1 && hitFrom == 0 ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 || board.GetPiecesAt( hitFrom + j ) < 2 ) hittingDices[i-1,j-1] = true; } else if ( i == j && ( board.GetPiecesAt( 0 ) == -1 || board.GetPiecesAt( 0 ) == -2 ) && board.GetPiecesAt( i ) < 2 ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 ) hittingDices[i-1,j-1] = true; } else if ( i == j && board.GetPiecesAt( 0 ) == -3 && hitFrom == 0 && board.GetPiecesAt( i ) < 2 ) { hittingDices[i-1,j-1] = true; } } else if ( i == j && ( distance == 3 * i || distance == 4 * i ) ) { if ( board.GetPiecesAt( 0 ) == 0 ) { if ( distance == 3 * i ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 && board.GetPiecesAt( hitFrom + ( i * 2 ) ) < 2 ) hittingDices[i-1,j-1] = true; } if ( distance == 4 * i ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 && board.GetPiecesAt( hitFrom + ( i * 2 ) ) < 2 && board.GetPiecesAt( hitFrom + ( i * 3 ) ) < 2 ) hittingDices[i-1,j-1] = true; } } else if ( ( board.GetPiecesAt( 0 ) == -1 && hitFrom == 0 ) ) { if ( distance == 3 * i ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 && board.GetPiecesAt( hitFrom + ( i * 2 ) ) < 2 ) hittingDices[i-1,j-1] = true; } if ( distance == 4 * i ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 && board.GetPiecesAt( hitFrom + ( i * 2 ) ) < 2 && board.GetPiecesAt( hitFrom + ( i * 3 ) ) < 2 ) hittingDices[i-1,j-1] = true; } } else if ( ( board.GetPiecesAt( 0 ) == -2 && hitFrom == 0 ) ) { if ( distance == 3 * i ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 && board.GetPiecesAt( hitFrom + ( i * 2 ) ) < 2 ) hittingDices[i-1,j-1] = true; } } else if ( board.GetPiecesAt( 0 ) == -1 && hitFrom != 0 && board.GetPiecesAt( i ) < 2 ) { if ( distance == 3 * i ) { if ( board.GetPiecesAt( hitFrom + i ) < 2 && board.GetPiecesAt( hitFrom + ( i * 2 ) ) < 2 ) hittingDices[i-1,j-1] = true; } } } } } }
public override LinguisticInputValue CreateLinguisticInputValue( BoardRepresentation board ) { LinguisticInputValue result = new LinguisticInputValue( GetName(), 0 ); float r = 0.0f; for ( int i = 1; i < 25; i++ ) { if ( board.GetPiecesAt( i ) == 1 ) { bool[,] possibleDices = new bool[6,6]; for ( int x = 0; x < 6; x++ ) for ( int y = 0; y < 6; y++ ) possibleDices[x,y] = false; for ( int j = 0; j < i; j++ ) if ( board.GetPiecesAt( j ) < 0 ) CalculateHitProbability( i, j, board, possibleDices ); int waysToBeHit = 0; for ( int x = 0; x < 6; x++ ) for ( int y = 0; y < 6; y++ ) if ( possibleDices[x,y] ) waysToBeHit++; float p = ( ((float)waysToBeHit) / 36.0f ) * 100; r += ((24.0f - ((float)i-1))/24.0f) * p; } } if ( r > 50.0f ) r = 50.0f; result.CrispValue = (int)Math.Round( r, 0 ); return result; }
public void Add(BoardRepresentation rep) { m_List.Add(rep); }
public override void GradeBoards( MoveRepresentationList list, BoardRepresentation initialBoard ) { bool race = Race( initialBoard ); for ( int i = 0; i < list.Count(); i++ ) { Grade( list.GetMoveRepresentation( i ), race, m_Output ); float regularLoseProberbilety = 1.0f - ( m_Output[0] + m_Output[1] + m_Output[2] + m_Output[3] + m_Output[4] ); double equity = m_Output[0] + (2 * m_Output[1]) + (3 * m_Output[2]) - regularLoseProberbilety - (2 * m_Output[3]) - (3 * m_Output[4]); list.GetMoveRepresentation( i ).AddScore( equity ); } }
public override void Learn( GameHistory history ) { BoardRepresentation[] boards = new BoardRepresentation[history.Count()]; for ( int i = boards.Length-1; i >= 0; i-- ) boards[i] = history.Peek( i ); int idx = boards.Length-1; int firstRaceBoardIdx = idx; for ( int i = 0; i < boards.Length; i++ ) { if ( Race( boards[i] ) ) { firstRaceBoardIdx = i; break; } } float[] wTarget = new float[5]; float[] lTarget = new float[5]; Grade( boards[idx], idx > firstRaceBoardIdx, wTarget ); Grade( boards[idx-1], (idx-1) > firstRaceBoardIdx, lTarget ); if ( history.WinType == 1 ) { wTarget[0] = wTarget[0] + ( STEP_SIZE * ( 1.0f - wTarget[0] ) ); wTarget[1] = wTarget[1] + ( STEP_SIZE * ( 0.0f - wTarget[1] ) ); wTarget[2] = wTarget[2] + ( STEP_SIZE * ( 0.0f - wTarget[2] ) ); wTarget[3] = wTarget[3] + ( STEP_SIZE * ( 0.0f - wTarget[3] ) ); wTarget[4] = wTarget[4] + ( STEP_SIZE * ( 0.0f - wTarget[4] ) ); lTarget[0] = lTarget[0] + ( STEP_SIZE * ( 0.0f - lTarget[0] ) ); lTarget[1] = lTarget[1] + ( STEP_SIZE * ( 0.0f - lTarget[1] ) ); lTarget[2] = lTarget[2] + ( STEP_SIZE * ( 0.0f - lTarget[2] ) ); lTarget[3] = lTarget[3] + ( STEP_SIZE * ( 0.0f - lTarget[3] ) ); lTarget[4] = lTarget[4] + ( STEP_SIZE * ( 0.0f - lTarget[4] ) ); } else if ( history.WinType == 2 ) { wTarget[0] = wTarget[0] + ( STEP_SIZE * ( 0.0f - wTarget[0] ) ); wTarget[1] = wTarget[1] + ( STEP_SIZE * ( 1.0f - wTarget[1] ) ); wTarget[2] = wTarget[2] + ( STEP_SIZE * ( 0.0f - wTarget[2] ) ); wTarget[3] = wTarget[3] + ( STEP_SIZE * ( 0.0f - wTarget[3] ) ); wTarget[4] = wTarget[4] + ( STEP_SIZE * ( 0.0f - wTarget[4] ) ); lTarget[0] = lTarget[0] + ( STEP_SIZE * ( 0.0f - lTarget[0] ) ); lTarget[1] = lTarget[1] + ( STEP_SIZE * ( 0.0f - lTarget[1] ) ); lTarget[2] = lTarget[2] + ( STEP_SIZE * ( 0.0f - lTarget[2] ) ); lTarget[3] = lTarget[3] + ( STEP_SIZE * ( 1.0f - lTarget[3] ) ); lTarget[4] = lTarget[4] + ( STEP_SIZE * ( 0.0f - lTarget[4] ) ); } else if ( history.WinType == 3 ) { wTarget[0] = wTarget[0] + ( STEP_SIZE * ( 0.0f - wTarget[0] ) ); wTarget[1] = wTarget[1] + ( STEP_SIZE * ( 0.0f - wTarget[1] ) ); wTarget[2] = wTarget[2] + ( STEP_SIZE * ( 1.0f - wTarget[2] ) ); wTarget[3] = wTarget[3] + ( STEP_SIZE * ( 0.0f - wTarget[3] ) ); wTarget[4] = wTarget[4] + ( STEP_SIZE * ( 0.0f - wTarget[4] ) ); lTarget[0] = lTarget[0] + ( STEP_SIZE * ( 0.0f - lTarget[0] ) ); lTarget[1] = lTarget[1] + ( STEP_SIZE * ( 0.0f - lTarget[1] ) ); lTarget[2] = lTarget[2] + ( STEP_SIZE * ( 0.0f - lTarget[2] ) ); lTarget[3] = lTarget[3] + ( STEP_SIZE * ( 0.0f - lTarget[3] ) ); lTarget[4] = lTarget[4] + ( STEP_SIZE * ( 1.0f - lTarget[4] ) ); } bool isCurrentBoardWinner = true; float[] prevWState = new float[5]; float[] prevLState = new float[5]; while ( idx >= 0 ) { if ( isCurrentBoardWinner ) { Train( boards[idx], idx > firstRaceBoardIdx, wTarget ); idx--; if ( idx > 0 ) { Grade( boards[idx-1], idx-1 > firstRaceBoardIdx, prevWState ); wTarget[0] = prevWState[0] + ( STEP_SIZE * ( wTarget[0] - prevWState[0] ) ); wTarget[1] = prevWState[1] + ( STEP_SIZE * ( wTarget[1] - prevWState[1] ) ); wTarget[2] = prevWState[2] + ( STEP_SIZE * ( wTarget[2] - prevWState[2] ) ); wTarget[3] = prevWState[3] + ( STEP_SIZE * ( wTarget[3] - prevWState[3] ) ); wTarget[4] = prevWState[4] + ( STEP_SIZE * ( wTarget[4] - prevWState[4] ) ); } } else { Train( boards[idx], idx > firstRaceBoardIdx, lTarget ); idx--; if ( idx > 0 ) { Grade( boards[idx-1], idx-1 > firstRaceBoardIdx, prevLState ); lTarget[0] = prevLState[0] + ( STEP_SIZE * ( lTarget[0] - prevLState[0] ) ); lTarget[1] = prevLState[1] + ( STEP_SIZE * ( lTarget[1] - prevLState[1] ) ); lTarget[2] = prevLState[2] + ( STEP_SIZE * ( lTarget[2] - prevLState[2] ) ); lTarget[3] = prevLState[3] + ( STEP_SIZE * ( lTarget[3] - prevLState[3] ) ); lTarget[4] = prevLState[4] + ( STEP_SIZE * ( lTarget[4] - prevLState[4] ) ); } } isCurrentBoardWinner = !isCurrentBoardWinner; } m_GamesTrained++; if ( m_GamesTrained % 100 == 0 ) Save( SAVE_FILE ); }
private void Train( BoardRepresentation board, bool race, float[] target ) { if ( race ) { SetRaceInput( board, m_RaceInput ); m_RaceNetwork.Train( m_RaceInput, target, MAX_SQUARE_ERROR, LEARNING_RATE ); } else { SetContactInput( board, m_ContactInput ); m_ContactNetwork.Train( m_ContactInput, target, MAX_SQUARE_ERROR, LEARNING_RATE ); } }
public override LinguisticInputValue CreateLinguisticInputValue( BoardRepresentation board ) { LinguisticInputValue result = new LinguisticInputValue( GetName(), board.BearOffCountCurrent() ); return result; }
public bool EndTurn() { FindWinner(); if ( m_Winner != BgPlayer.None ) { BoardRepresentation finalBoard = new BoardRepresentation( this ); if ( m_History.Count() > 0 && !m_History.PeekLast().PatternMatches( finalBoard ) ) { m_History.Add( finalBoard ); m_History.Winner = m_Winner; m_History.WinType = VictoryType(); } return false; } if ( !IsMovesUsed() ) if ( DoesValidMoveExist() ) return false; m_History.Add( new BoardRepresentation( this ) ); m_UndoStack.Clear(); m_CurrentPlayer = CurrentOpponentPlayer; SetCorrectlySwitchedBoard(); RollDices(); m_MaxMovesPossible = MaxMovesPossible( 0 ); return true; }
private void Grade( BoardRepresentation board, bool race, float[] grade ) { if ( race ) { SetRaceInput( board, m_RaceInput ); m_RaceNetwork.Run( m_RaceInput, grade ); } else { SetContactInput( board, m_ContactInput ); m_ContactNetwork.Run( m_ContactInput, grade ); } }