Exemple #1
0
 public static int robber_moves_randomBeacon(Board board, int r, int goOnTime, Robber robber, Cop cop)
 {
     int node = 0;
     if ((robber.movesSoFar == goOnTime || robber.movesSoFar == 1 || robber.myPath.Count <= robber.movesSoFar))
     {
         robber.movesSoFar = 1;
         robber.myPath = getBeaconNodes(r, 1, board, cop, robber);
         //robber.move(robber.myPath[robber.movesSoFar], board);
         node = robber.myPath[robber.movesSoFar];
         robber.movesSoFar++;
     }
     else
     {
         //robber.move(robber.myPath[robber.movesSoFar], board);
         node = robber.myPath[robber.movesSoFar];
         robber.movesSoFar++;
     }
     return node;
 }
Exemple #2
0
        private void plansza_MouseDown(object sender, MouseButtonEventArgs e)
        {
            string elem = findElement(sender, e);

            if (elem == null || elem == "")
            {
            }
            else if (elem != "" && elem.Substring(0, 3) == "nod")
            {
                clickedElement = Convert.ToInt32(elem.Substring(4, elem.Length - 4));
                if (copTurn)
                {
                    if (copPlaced)
                    {
                        if (cop.myNeighbors.Contains(clickedElement))
                        {
                            checkboard.Children.Remove(cop.myNode.elly);
                            cop.myNode.number = clickedElement;
                            cop.myNeighbors   = board.findNeighbors(cop.myNode.number);
                            board.pointCop(findPoint(elem), cop.myNode);
                            checkboard.Children.Add(cop.myNode.elly);
                            RobberMove();
                        }
                        else
                        {
                            cop.myNeighbors = board.findNeighbors(cop.myNode.number);
                            MessageBox.Show("tak daleko nie dobiegnę...");
                        }
                    }
                    else
                    {
                        int tmp;
                        cop = new Cop(board, findPoint(elem, out tmp), tmp);
                        checkboard.Children.Add(cop.myNode.elly);
                        copPlaced    = true;
                        copTurn      = false;
                        lblTura.Text = "Złodziej";
                    }
                }
                else
                {
                    if (!robberPlaced)
                    {
                        int tmp;
                        robber = new Robber(board, findPoint(elem, out tmp), tmp);
                        checkboard.Children.Add(robber.myNode.elly);
                        robberPlaced = true;
                        copTurn      = true;
                        lblTura.Text = "Gliniarz";
                    }
                }
            }
            else if (elem.Substring(0, 3) == "rob" || elem.Substring(0, 3) == "cop")
            {
                if (copTurn)
                {
                    if (cop.myNeighbors.Contains(robber.myNode.number))
                    {
                        gameEnd("cop");
                    }
                    else
                    {
                        MessageBox.Show("jeszcze za daleko");
                    }
                }
                else
                {
                    if (robber.myNeighbors.Contains(cop.myNode.number))
                    {
                        gameEnd("robber");
                    }
                    else
                    {
                        MessageBox.Show("no widze go i co?!");
                    }
                }
            }
        }
Exemple #3
0
 public static int robber_moves_greedy_dumb(Cop cop, Robber robber)
 {
     for (int i = 0; i < robber.myNeighbors.Count; i++ )
     {
         Random rand = new Random();
         int tmp = robber.myNeighbors[rand.Next(robber.myNeighbors.Count-1)];
         if (tmp != cop.myNode.number)
         {
             return tmp;
         }
     }
     foreach (int item in robber.myNeighbors)
     {
         if (item!= cop.myNode.number)
         {
             return item;
         }
     }
     return -1;
 }
Exemple #4
0
        public static int robber_moves_greedy_dijkstra(int copnumber, Board board, Cop cop, Robber robber)
        {
            List<int> currentPath = new List<int>();
            List<int> bestPath = new List<int>();
            List<List<int>> currentPathToCops = new List<List<int>>();
            bool defeat = false;
            int pathLength = 0;
            if (robber.myNeighbors.Contains(cop.ocupiedNode))
                defeat = true;

            foreach (int item in robber.myNeighbors)
            {
                if (item != cop.myNode.number)
                {
                    currentPath = Dijkstra(robber.ocpupiedNode, item, cop.ocupiedNode, board);
                    currentPathToCops.Add(currentPath);

                    foreach (List<int> tmp in currentPathToCops)
                    {
                        if (pathLength == 0 || pathLength < tmp.Count)
                        {
                            pathLength = tmp.Count;
                            currentPath = tmp;
                        }
                    }
                    defeat = false;
                    if (bestPath.Count < currentPath.Count)
                        bestPath = currentPath;
                    currentPathToCops.Clear();
                }
            }
            if (!defeat)
            {
                try
                {
                    return bestPath[0];
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ruch złodzieja" + ex);
                }
            }
            return -1;
        }
Exemple #5
0
        public static List<int> getBeaconNodes(int r, int copnumber, Board board, Cop cop, Robber robber)
        {
            List<int> path = new List<int>();
            List<int> bestPath = new List<int>();
            List<List<int>> currentPathToCops = new List<List<int>>();
            int bestNode = 0, pathLength = 0;
            int node;
            for (int randNumber = 0; randNumber < r; randNumber++)
            {
                node = board.random.Next(board.neighbor.Count);
                if (cop.ocupiedNode != node)
                {
                    path = Dijkstra(node, node, cop.ocupiedNode, board);
                    currentPathToCops.Add(path);

                }
                foreach (List<int> tmp in currentPathToCops)
                {
                    if (pathLength == 0 || pathLength > tmp.Count)
                    {
                        pathLength = tmp.Count;
                        path = tmp;
                    }
                }
                if (path.Count > bestPath.Count || bestPath.Count == 0)
                {
                    bestPath = path;
                    bestNode = node;
                }
                currentPathToCops.Clear();
            }
            return Dijkstra(robber.ocpupiedNode, robber.ocpupiedNode, bestNode, board);
        }
Exemple #6
0
 /// <summary>
 /// creating new board robber and cops for new series of runaways
 /// </summary>        
 private void newDataForTest(int copnumber)
 {
     List<int> notSafe = new List<int>();
     cops = new List<Cop>();
     ocupied = new List<int>();
     board = new Board(nodenumberMin, nodenumberMax, maxNodeSt);
     int nodenumber = board.neighbor.Count;
     int i;
     for (i = 0; i < copnumber; i++)
     {
         cops.Add(new Cop(board.random.Next(nodenumber), board));
         cops[i].copId = i;
         if (!ocupied.Contains(cops[i].ocupiedNode))
         {
             ocupied.Add(cops[i].ocupiedNode);
             cops[i].startNode = cops[i].ocupiedNode;
         }
         else
         {
             do
             {
                 cops[i] = new Cop(board.random.Next(nodenumber), board);
                 cops[i].startNode = cops[i].ocupiedNode;
             } while (ocupied.Contains(cops[i].startNode));
             ocupied.Add(cops[i].startNode);
         }
     }
     foreach (Cop cop in cops)
     {
         foreach (int a in cop.myNeighbors)
         {
             notSafe.Add(a);
         }
     }
     i = 0;
     do
     {
         i++;
         robber = new Robber(board.random.Next(nodenumber), board);
         robber.startNode = robber.ocpupiedNode;
         if (i > 100) newDataForTest(copnumber);
     } while (ocupied.Contains(robber.ocpupiedNode) || notSafe.Contains(robber.ocpupiedNode));
 }
        private void plansza_MouseDown(object sender, MouseButtonEventArgs e)
        {
            string elem = findElement(sender, e);
            if (elem == null || elem == "")
            {
            }
            else if (elem != "" && elem.Substring(0, 3) == "nod")
            {
                clickedElement = Convert.ToInt32(elem.Substring(4, elem.Length - 4));
                if (copTurn)
                {
                    if (copPlaced)
                    {
                        if (cop.myNeighbors.Contains(clickedElement))
                        {
                            checkboard.Children.Remove(cop.myNode.elly);
                            cop.myNode.number = clickedElement;
                            cop.myNeighbors = board.findNeighbors(cop.myNode.number);
                            board.pointCop(findPoint(elem), cop.myNode);
                            checkboard.Children.Add(cop.myNode.elly);
                            RobberMove();

                        }
                        else
                        {
                            cop.myNeighbors = board.findNeighbors(cop.myNode.number);
                            MessageBox.Show("tak daleko nie dobiegnę...");
                        }
                    }
                    else
                    {
                        int tmp;
                        cop = new Cop(board, findPoint(elem, out tmp), tmp);
                        checkboard.Children.Add(cop.myNode.elly);
                        copPlaced = true;
                        copTurn = false;
                        lblTura.Text = "Złodziej";
                    }
                }
                else
                {
                    if (!robberPlaced)
                    {

                        int tmp;
                        robber = new Robber(board, findPoint(elem, out tmp), tmp);
                        checkboard.Children.Add(robber.myNode.elly);
                        robberPlaced = true;
                        copTurn = true;
                        lblTura.Text = "Gliniarz";
                    }
                }
            }
            else if (elem.Substring(0, 3) == "rob" || elem.Substring(0, 3) == "cop")
            {
                if (copTurn)
                {
                    if (cop.myNeighbors.Contains(robber.myNode.number))
                    {
                        gameEnd("cop");
                    }
                    else
                        MessageBox.Show("jeszcze za daleko");
                }
                else
                {
                    if (robber.myNeighbors.Contains(cop.myNode.number))
                    {
                        gameEnd("robber");
                    }
                    else
                        MessageBox.Show("no widze go i co?!");
                }
            }
        }