Beispiel #1
0
        private void ClickedAHole(object sender, System.EventArgs e)
        {
            try
            {
                int holeIdx = holes.IndexOf(sender);

                if (pegToMove == -1)
                {
                    pegToMove = holeIdx;
                }
                else
                {
                    if (pegToMove != holeIdx)
                    {
                        pegDestination = holeIdx;
                        theGame.Move(pegToMove, pegDestination);
                        if (theGame.GameOver)
                        {
                            setTheBoard();
                            MessageBox.Show("there are no moves left");
                        }
                        //MessageBox.Show(String.Format("The Best Possible Score is {0}",gameDomain.BestPossibleScore(theGame.Signature)));
                    }
                    pegToMove      = -1;
                    pegDestination = -1;
                }
                setTheBoard();
            }
            catch (Exception except)
            {
                pegToMove      = -1;
                pegDestination = -1;
                MessageBox.Show(except.Message);
            }
        }
Beispiel #2
0
 static void BuildTree(GameNode root)
 {
     //build children
     foreach (MoveTuple mv in root.Game.AvailableMoves)
     {
         trianglePegs.game child = root.Game.Clone();
         child.Move(mv.original, mv.destination);
         Int64 childSig = child.Signature;
         if (!uniqueGameStates.Contains(childSig))
         {
             GameNode gnChild = new GameNode(child);
             root.Children.Add(gnChild);
             uniqueGameStates.Add(childSig, gnChild);
             BuildTree(gnChild);
         }
     }
 }