Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to check if pieces are ordered

How to check if pieces are ordered

Scheduled Pinned Locked Moved C#
csharpdata-structurestutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aleksandar Jeftic
    wrote on last edited by
    #1

    picture 1 picture 2 I made method for checking if all pieces are in base or goal if yes it returns true,now i need another method. If pieces are ordered like on Picture 1. i need to change number of throws to 3 ,if pieces are ordered like on Picture 2 i can allow only 1 throw cos of empty space between. I got 4 goalPositions and 4 piecePositions,and need to check if pieces are ordered on them from 54-51 path positions(path is array of 55 fields 0-54) ,if yes return true if not return false. I am new to C# never had chance to work with order checking till now. I was trying to do it with 3 int lists goalPositions (populated with 51,52,53,54 path positions),piecePositions(populated with pieces positions with getPosition()),and piecesOnGoal. but no luck with that. ill add some code. part of player class with that lists and method for checking pieces in goal or base

    class Player
    {
    protected PieceSet[] pieces;
    Color color;
    int numberOfThrows;
    Dice dice;
    public List goalPositions;
    public List piecePositions;
    public List piecesOnGoal;

        public enum Color
        {
            Yellow, Green, Blue, Red
        }
    
        public Player(Color color)
        {
            int\[\] path = new int\[55\];
            this.color = color;
            dice = new Dice();
            numberOfThrows = 3;
            switch (color)
            {
                case Color.Yellow:
                    path = BoardHelper.getYellowPath();
                    break;
                case Color.Green:
                    path = BoardHelper.getGreenPath();
                    break;
                case Color.Blue:
                    path = BoardHelper.getBluePath();
                    break;
                case Color.Red:
                    path = BoardHelper.getRedPath();
                    break;
            }
            pieces = new PieceSet\[4\];
            pieces\[0\] = new PieceSet(path, 0);
            pieces\[1\] = new PieceSet(path, 1);
            pieces\[2\] = new PieceSet(path, 2);
            pieces\[3\] = new PieceSet(path, 3);
    
            piecePositions = new List(4);
            piecePositions.Add(pieces\[0\].getPosition());
            piecePositions.Add(pieces\[1\].getPosition());
            piecePositions.Add(pieces\[2\].getPosition());
    
    P F 2 Replies Last reply
    0
    • A Aleksandar Jeftic

      picture 1 picture 2 I made method for checking if all pieces are in base or goal if yes it returns true,now i need another method. If pieces are ordered like on Picture 1. i need to change number of throws to 3 ,if pieces are ordered like on Picture 2 i can allow only 1 throw cos of empty space between. I got 4 goalPositions and 4 piecePositions,and need to check if pieces are ordered on them from 54-51 path positions(path is array of 55 fields 0-54) ,if yes return true if not return false. I am new to C# never had chance to work with order checking till now. I was trying to do it with 3 int lists goalPositions (populated with 51,52,53,54 path positions),piecePositions(populated with pieces positions with getPosition()),and piecesOnGoal. but no luck with that. ill add some code. part of player class with that lists and method for checking pieces in goal or base

      class Player
      {
      protected PieceSet[] pieces;
      Color color;
      int numberOfThrows;
      Dice dice;
      public List goalPositions;
      public List piecePositions;
      public List piecesOnGoal;

          public enum Color
          {
              Yellow, Green, Blue, Red
          }
      
          public Player(Color color)
          {
              int\[\] path = new int\[55\];
              this.color = color;
              dice = new Dice();
              numberOfThrows = 3;
              switch (color)
              {
                  case Color.Yellow:
                      path = BoardHelper.getYellowPath();
                      break;
                  case Color.Green:
                      path = BoardHelper.getGreenPath();
                      break;
                  case Color.Blue:
                      path = BoardHelper.getBluePath();
                      break;
                  case Color.Red:
                      path = BoardHelper.getRedPath();
                      break;
              }
              pieces = new PieceSet\[4\];
              pieces\[0\] = new PieceSet(path, 0);
              pieces\[1\] = new PieceSet(path, 1);
              pieces\[2\] = new PieceSet(path, 2);
              pieces\[3\] = new PieceSet(path, 3);
      
              piecePositions = new List(4);
              piecePositions.Add(pieces\[0\].getPosition());
              piecePositions.Add(pieces\[1\].getPosition());
              piecePositions.Add(pieces\[2\].getPosition());
      
      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Aleksandar Jeftic wrote:

      Its kind of urgent.

      Not to us.

      A 1 Reply Last reply
      0
      • A Aleksandar Jeftic

        picture 1 picture 2 I made method for checking if all pieces are in base or goal if yes it returns true,now i need another method. If pieces are ordered like on Picture 1. i need to change number of throws to 3 ,if pieces are ordered like on Picture 2 i can allow only 1 throw cos of empty space between. I got 4 goalPositions and 4 piecePositions,and need to check if pieces are ordered on them from 54-51 path positions(path is array of 55 fields 0-54) ,if yes return true if not return false. I am new to C# never had chance to work with order checking till now. I was trying to do it with 3 int lists goalPositions (populated with 51,52,53,54 path positions),piecePositions(populated with pieces positions with getPosition()),and piecesOnGoal. but no luck with that. ill add some code. part of player class with that lists and method for checking pieces in goal or base

        class Player
        {
        protected PieceSet[] pieces;
        Color color;
        int numberOfThrows;
        Dice dice;
        public List goalPositions;
        public List piecePositions;
        public List piecesOnGoal;

            public enum Color
            {
                Yellow, Green, Blue, Red
            }
        
            public Player(Color color)
            {
                int\[\] path = new int\[55\];
                this.color = color;
                dice = new Dice();
                numberOfThrows = 3;
                switch (color)
                {
                    case Color.Yellow:
                        path = BoardHelper.getYellowPath();
                        break;
                    case Color.Green:
                        path = BoardHelper.getGreenPath();
                        break;
                    case Color.Blue:
                        path = BoardHelper.getBluePath();
                        break;
                    case Color.Red:
                        path = BoardHelper.getRedPath();
                        break;
                }
                pieces = new PieceSet\[4\];
                pieces\[0\] = new PieceSet(path, 0);
                pieces\[1\] = new PieceSet(path, 1);
                pieces\[2\] = new PieceSet(path, 2);
                pieces\[3\] = new PieceSet(path, 3);
        
                piecePositions = new List(4);
                piecePositions.Add(pieces\[0\].getPosition());
                piecePositions.Add(pieces\[1\].getPosition());
                piecePositions.Add(pieces\[2\].getPosition());
        
        F Offline
        F Offline
        Freak30
        wrote on last edited by
        #3

        I would do the check in stages. For the piecesOnGoal you only need the count, not the individual numbers. So start like this:

        int piecesOnGoal = 0, piecesOnBase = 0;
        for (int i = 0; i < 4; i++)
        {
        if (piecePositions[i] > 50)
        piecesOnGoal++;
        else if (piecePositions[i] < 4)
        piecesOnBase++;
        }

        // If pieces on base and in goal don't add up to 4, return false.
        // If pieces on base is 4, rturn true.

        for (int i = 0; i < piecesOnGoal; i++)
        {
        // Check here that piecePositions contains an element 54 - i.
        // if there is none, return false.
        }

        return true;

        The good thing about pessimism is, that you are always either right or pleasently surprised.

        1 Reply Last reply
        0
        • P PIEBALDconsult

          Aleksandar Jeftic wrote:

          Its kind of urgent.

          Not to us.

          A Offline
          A Offline
          Aleksandar Jeftic
          wrote on last edited by
          #4

          thx for your useless comment

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups