Ejemplo n.º 1
0
        /// <summary>
        /// Adds Linevalue to Totalvalue before setting it to 0, preparing to evaluate the next line.
        /// </summary>
        public void NewLine()
        {
            //careful about reporting multiple threats on the same line
            //TODO: known missed win is "o_ooo_o" (and maybe some similar) but these *should* be rare
            // the false wins involving 6 in a row or something are more frequent
            if (lb4)
            {
                black4++;
            }
            else if (lb3)
            {
                black3++;
            }
            if (lw4)
            {
                white4++;
            }
            else if (lw3)
            {
                white3++;
            }

            TotalValue += LineValue;
            LineValue   = 0;
            lb4         = false;
            lb3         = false;
            lw4         = false;
            lw3         = false;
            CurrentNode = Root;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the automaton using patterns from HeuristicValues.cs
        /// </summary>
        public void BuildAutomaton()
        {
            Root = new ACNode();
            FillTree();
            Queue <ACNode> q = new Queue <ACNode>();

            foreach (ACNode son in Root.Forward)
            {
                if (null == son)
                {
                    continue;
                }
                q.Enqueue(son);
                son.Back = Root;
            }
            ACNode i, z, s;

            while (q.Count != 0)
            {
                i = q.Dequeue();
                for (byte b = 0; b <= 2; b++)
                {
                    s = i.Forward[b];
                    if (null == s)
                    {
                        continue;
                    }

                    z = i.Back;
                    while ((null == z.Forward[b]) && (z != Root))
                    {
                        z = z.Back;
                    }
                    if (null != z.Forward[b])
                    {
                        z = z.Forward[b];
                    }
                    s.Back = z;
                    if (z.Value != 0)
                    {
                        s.Shortcut = z;
                    }
                    else
                    {
                        s.Shortcut = z.Shortcut;
                    }

                    q.Enqueue(s);
                }
            }
            CurrentNode = Root;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generate tree nodes for the given word and assign the value to the last node.
        /// </summary>
        private void AddWord(IEnumerable <Byte> word, int value)
        {
            ACNode node = Root;

            foreach (byte b in word)
            {
                if (null == node.Forward[b])
                {
                    node.Forward[b] = new ACNode();
                }
                node = node.Forward[b];
            }
            node.Value = value;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets all values to 0, preparing to evaluate a new board, with the indication of whose turn it is.
 /// </summary>
 public void Reset(bool black)
 {
     blackToMove = black;
     LineValue   = 0;
     TotalValue  = 0;
     CurrentNode = Root;
     black4      = 0;
     black3      = 0;
     white4      = 0;
     white3      = 0;
     lb4         = false;
     lb3         = false;
     lw4         = false;
     lw3         = false;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Give a square's value to the automaton; called one-by-one for an entire line.
        /// </summary>
        public void FeedSquare(byte b)
        {
            //update current node based on the read square
            while ((null == CurrentNode.Forward[b]) && (CurrentNode != Root))
            {
                CurrentNode = CurrentNode.Back;
            }
            if (null != CurrentNode.Forward[b])
            {
                CurrentNode = CurrentNode.Forward[b];
            }

            //update value based on node's value and shortcuts
            ShortcutProbe = CurrentNode;
            while (null != ShortcutProbe)
            {
                checkScore(ShortcutProbe.Value);
                LineValue    += ShortcutProbe.Value;
                ShortcutProbe = ShortcutProbe.Shortcut;
            }
        }