Example #1
0
 /*
  * Method to find all Valid Moves Diagonal Bottom-left to Top-right
  * pos0 is x-coordinate , pos1 is y-coordinate in Map(position of my stone)
  * field is the playing map
  * j is for calculation ( j can be -1 or 1)
  * in List are integer with value -1(cannot move),0(can move),1 (priority move for jump)
  */
 public List<int> BotleftToTopright(int pos0, int pos1, Map field, int j)
 {
     List<int> ret = new List<int>(); // return list
     int[] pos = new int[2] { pos0, pos1 };//position of your stone
     PlayerColor pc = PlayerColor.White;
     if (field.Field[pos0, pos1] != null  && field.Field[pos0, pos1].Color == pc)// set opponent Color
         pc = PlayerColor.Black;
     for (int i = 0; i < field.Field.GetLength(1); ++i)
     {
         pos[0] += j * 1;    // Move your stone imaginary to find out, if you can move there
         pos[1] -= j * 1;
         if (field.isOnTheMap(pos))// is the field on the map?
         {
             if (field.Field[pos[0],pos[1]] == null)// is empty
             {
                 ret.Add(0);    //you can move to this field
             }
             else if (field.Field[pos[0],pos[1]].Color == pc)// is enemystone on the field?
             {
                 pos[0] += j * 1;
                 pos[1] -= j * 1;
                 if (field.isOnTheMap(pos))  // Can you jump over enemy?
                 {
                     var temp = field.Field[pos[0], pos[1]];
                     if (temp == null)
                     {
                         ret.Add(-1);// Enemy field
                         ret.Add(1);// You can move to this field with priority
                         i++;// inc i because adding 2 fields
                     }
                     else
                     {
                         ret.Add(-1);
                         ret.Add(-1);
                         ++i;
                     }
                 }
             }
             else// Your ally stone is on field
             {//add twice  -1 so that method can see you are not able to move there and behind.
                 ret.Add(-1);
                 ret.Add(-1);
             }
         }
     }
     for (int c = 0; c < ret.Count - 2; ++c)
     {
         if (ret[c] == ret[c + 1] && ret[c] == -1) // if you cannot move twice in a row
         {
             for (int b = ret.Count -1; b > c; --b)// All fields behind will not be accesable
             {
                 ret.RemoveAt(b);
                 ret.Add(-1);
             }
         }
     }
     return ret;
 }
Example #2
0
 /*
  * Method to find all Valid Moves Diagonal Bottom-right to Top-öeft
  * pos0 is x-coordinate , pos1 is y-coordinate in Map(position of my stone)
  * field is the playing map
  * j is for calculation ( j can be -1 or 1)
  * in List are integer with value -1(cannot move),0(can move),1 (priority move for jump)
  */
 public List<int> BotrightToTopleft(int pos0, int pos1, Map field, int j)
 {
     List<int> ret = new List<int>();// return List
     int[] pos = new int[2] { pos0, pos1 };//Your Position
     PlayerColor pc = PlayerColor.White;
     if (field.Field[pos0, pos1] != null && field.Field[pos0, pos1].Color == pc)//set enemy Color
         pc = PlayerColor.Black;
     for (int i = 0; i < field.Field.GetLength(1); ++i)
     {
         pos[0] += j * 1;// Field in diagonal way
         pos[1] += j * 1;
         if (field.isOnTheMap(pos))// is Field on map?
         {
             if (field.Field[pos[0], pos[1]] == null)// is empty
             {
                 ret.Add(0);    //you can move to this field
             }
             else if (field.Field[pos[0], pos[1]].Color == pc)// is on requested field enemy?
             {
                 pos[0] += j * 1;//look behind enemy
                 pos[1] += j * 1;
                 if (field.isOnTheMap(pos))//Can you jump over enemy?
                 {
                     var temp = field.Field[pos[0], pos[1]];
                     if (temp == null)
                     {
                         ret.Add(-1);//field where enemy is standing
                         ret.Add(1);// You can move to this field with priority
                         ++i;
                     }
                     else
                     {
                         ret.Add(-1);
                         ret.Add(-1);
                         ++i;
                     }
                 }
             }
             else//Ally stone on field
             {
                 ret.Add(-1);
                 ret.Add(-1);
             }
         }
     }
     for (int c = 0; c < ret.Count - 2; ++c)
     {
         if (ret[c] == ret[c + 1] && ret[c] == -1)// if you cannot move twice in a row
         {
             for (int b = ret.Count - 1; b > c; --b)// all fields behind are not accesible
             {
                 ret.RemoveAt(b);// Removes all entrys till there
                 ret.Add(-1);// add -1 for not reachable
             }
         }
     }
     return ret;
 }