public void GeneratePossibleRepresentations(MoveRepresentationList knowledgeList)
        {
            string currentPattern = m_PatternEncoder.Encode(m_BgGame);

            if (!currentPattern.Equals(m_CurrentGeneratedPattern))
            {
                m_CurrentGeneratedMoves.Clear();
                m_MoveGenerator.GenerateMoves(m_MoveList);

                for (int i = 0; i < m_MoveList.Count(); i++)
                {
                    MoveRepresentation possibleMove = new MoveRepresentation(m_BgGame, m_MoveList.GetBgMove(i));
                    m_CurrentGeneratedMoves.AddMoveRepresentation(possibleMove, false);
                }

                m_CurrentGeneratedPattern = currentPattern;
            }

            knowledgeList.Clear();

            for (int i = 0; i < m_CurrentGeneratedMoves.Count(); i++)
            {
                knowledgeList.AddMoveRepresentation(m_CurrentGeneratedMoves.GetMoveRepresentation(i).GetClone(), true);
            }
        }
 public void AddMoveRepresentation(MoveRepresentation MoveRepresentation, bool addIfExists)
 {
     if (addIfExists || !DoesMoveRepresentationExist(MoveRepresentation))
     {
         m_List.Add(MoveRepresentation);
     }
 }
示例#3
0
        public BgMove CommitMove()
        {
            if (IsAgentMoveing() && m_MoveRepresentationList.Count() > 0)
            {
                int    numBestMoves  = 1;
                double bestMoveScore = m_MoveRepresentationList.GetMoveRepresentation(0).GetScore();
                for (int i = 1; i < m_MoveRepresentationList.Count(); i++)
                {
                    double currentCompareMoveScore = m_MoveRepresentationList.GetMoveRepresentation(i).GetScore();
                    if (bestMoveScore == currentCompareMoveScore)
                    {
                        numBestMoves++;
                    }
                    else
                    {
                        break;
                    }
                }

                int selectedMove = m_Rand.Next(numBestMoves);

                MoveRepresentation bestMove = m_MoveRepresentationList.GetMoveRepresentation(selectedMove);
                BgMove             m        = bestMove.GetMoves().FirstMove;
                while (m != null)
                {
                    m_BgGame.MakeMove(m.From, m.To);
                    m = m.NextMove;
                }
                return(bestMove.GetMoves());
            }
            else
            {
                return(null);
            }
        }
        private bool DoesMoveRepresentationExist(MoveRepresentation move)
        {
            for (int i = 0; i < m_List.Count; i++)
            {
                if ((( MoveRepresentation )m_List[i]).PatternMatches(move))
                {
                    return(true);
                }
            }

            return(false);
        }
        public MoveRepresentation GetClone()
        {
            MoveRepresentation result = new MoveRepresentation( null );

            result.m_BoardPattern = new int[m_BoardPattern.Length];
            for ( int i = 0; i < m_BoardPattern.Length; i++ )
                result.m_BoardPattern[i] = m_BoardPattern[i];

            result.m_Move = BgMove.CloneFromFirst( m_Move.FirstMove );
            result.m_Score = m_Score;

            return result;
        }
        public MoveRepresentation GetClone()
        {
            MoveRepresentation result = new MoveRepresentation(null);

            result.m_BoardPattern = new int[m_BoardPattern.Length];
            for (int i = 0; i < m_BoardPattern.Length; i++)
            {
                result.m_BoardPattern[i] = m_BoardPattern[i];
            }

            result.m_Move  = BgMove.CloneFromFirst(m_Move.FirstMove);
            result.m_Score = m_Score;

            return(result);
        }
        public void GeneratePossibleRepresentations( MoveRepresentationList knowledgeList )
        {
            string currentPattern = m_PatternEncoder.Encode( m_BgGame );

            if ( !currentPattern.Equals( m_CurrentGeneratedPattern ) )
            {
                m_CurrentGeneratedMoves.Clear();
                m_MoveGenerator.GenerateMoves( m_MoveList );

                for ( int i = 0; i < m_MoveList.Count(); i++ )
                {
                    MoveRepresentation possibleMove = new MoveRepresentation( m_BgGame, m_MoveList.GetBgMove( i ) );
                    m_CurrentGeneratedMoves.AddMoveRepresentation( possibleMove, false );
                }

                m_CurrentGeneratedPattern = currentPattern;
            }

            knowledgeList.Clear();

            for ( int i = 0; i < m_CurrentGeneratedMoves.Count(); i++ )
                knowledgeList.AddMoveRepresentation( m_CurrentGeneratedMoves.GetMoveRepresentation( i ).GetClone(), true );
        }
        private bool DoesMoveRepresentationExist( MoveRepresentation move )
        {
            for ( int i = 0; i < m_List.Count; i++ )
                if ( ( ( MoveRepresentation )m_List[i] ).PatternMatches( move ) )
                    return true;

            return false;
        }
 public void AddMoveRepresentation( MoveRepresentation MoveRepresentation, bool addIfExists )
 {
     if ( addIfExists || !DoesMoveRepresentationExist( MoveRepresentation ) )
         m_List.Add( MoveRepresentation );
 }