예제 #1
0
        public int hint(bool black)
        {
            int score = -1;

            isBlack       = black;
            int[,] scores = new int[8, 8];
            int maxR = 0;
            int maxC = 0;

            for (int r = 0; r < 8; r++)
            {
                for (int c = 0; c < 8; c++)
                {
                    Space here = board.board[r, c];
                    if (here.status != 0)
                    {
                        continue;
                    }
                    here.placeDisc(black);
                    int flips = findFlips(here, true);
                    toFlip.Clear();
                    if (flips > 0)
                    {
                        //MessageBox.Show(r+","+c+" has "+flips);
                        scores[r, c] = flips;
                        toHint.Add(here);
                        if (flips > scores[maxR, maxC])
                        {
                            maxR = r;
                            maxC = c;
                        } //if max
                    }     // if positive (unnec?)
                    here.eraseDisc();
                }         //for c
            }             //for r
            //MessageBox.Show("max is " + scores[maxR, maxC] + " at " + maxR + ", " + maxC);
            if (scores[maxR, maxC] == 0)
            {
                return(0);
            }
            Space max = board.board[maxR, maxC];

            //MessageBox.Show("Max is at " + maxR + "," + maxC + " with flips: "+scores[maxR,maxC]);
            foreach (Space spot in toHint)
            {
                //spot.placeDisc(!isBlack);
                //findFlips(spot, true);
                //spot.highLight();
            }
            //max.placeDisc(!isBlack);
            //findFlips(max, true);
            toHint.ForEach(hint);
            toFlip.ForEach(highlight);
            //max.highLight();
            //return score
//                max.unhighLight();
            toFlip.Clear();
            //if (score == -1)
            //{
            //    return -1;
            //}
            //if (black)
            //{
            //    blackPlayer.decCount();
            //    blackStack.drawStack(blackPlayer.discsLeft);
            //    blackPlayer.raiseScore(score + 1);
            //    whitePlayer.lowerScore(score);
            //}
            //else
            //{
            //    whitePlayer.decCount();
            //    whiteStack.drawStack(whitePlayer.discsLeft);
            //    whitePlayer.raiseScore(score + 1);
            //    blackPlayer.lowerScore(score);
            //}
            return(score);
        }//method
예제 #2
0
 public static void unhint(Space s)
 {
     s.unhint(isBlack);
 }
예제 #3
0
 public static void confirmHint(Space s)
 {
     s.confirmHint(isBlack);
 }
예제 #4
0
 public static void hint(Space s)
 {
     s.hint(isBlack);
 }
예제 #5
0
 public static void unhighlight(Space s)
 {
     s.unhighLight();
 }
예제 #6
0
 public static void confirm(Space s)
 {
     s.confirm();
 }
예제 #7
0
        }         //method

        public static void highlight(Space s)
        {
            s.highLight();
        }
예제 #8
0
        public int findFlips(Space sp, bool isHintSearch)
        {
            int score = -1;

            for (int d = 0; d < 8; d++)
            {
                List <Space> tentative = new List <Space>();
                Space        m         = next(sp, d);
                while (m != null && m.status != 0 && m.status != sp.status)
                {
                    tentative.Add(m);
                    m = next(m, d);
                }
                if (m == null || m.status == 0)
                {
                    tentative.Clear();
                }
                else if (m.status != sp.status)
                {
                    tentative.Clear();
                }
                else if (m.status == sp.status)
                {
                    tentative.Remove(m);
                    toFlip.AddRange(tentative);
                }
                else
                {
                    MessageBox.Show("last space is: " + m.status);
                }
            }//for each direction
            //MessageBox.Show("Number to flip: " + toFlip.Count());
            if (!isHintSearch)
            {
                if (toFlip.Count() <= 0)
                {
                    MessageBox.Show("Illegal move! Try again!");
                    sp.eraseDisc();
                    return(-1);
                    //bad move!
                }
                else
                {
                    toFlip.ForEach(highlight);
                    toFlip.ForEach(confirm);
                    //return score
                    score = toFlip.Count();
                    //toFlip.Clear();
                    return(score);

                    /*
                     * DialogResult answer = MessageBox.Show("Confirm that move?", "Confirm?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                     * if (answer == DialogResult.Yes)
                     * {
                     *  toFlip.ForEach(confirm);
                     *  //return score
                     *  score = toFlip.Count();
                     *  toFlip.Clear();
                     *  return score;
                     * }
                     *
                     * else if (answer == DialogResult.No)
                     * {
                     *  toFlip.ForEach(unhighlight);
                     *  //return score
                     *  sp.eraseDisc();
                     *  sp.unhighLight();
                     *  toFlip.Clear();
                     *  return -1;
                     * }
                     */
                    return(score);
                } //flips pos
            }     //is hint search
            return(toFlip.Count());
        }         //method