コード例 #1
0
ファイル: Draught.cs プロジェクト: CedricHanebaum/Dame
 /*
  * 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;
 }
コード例 #2
0
ファイル: Human.cs プロジェクト: CedricHanebaum/Dame
 public int[] SetStep(Map m, Token.PlayerColor color, int[] p, int check, Control contrl, List<int[]> taken)
 {
     int[] pos = ChooseToken(m, color, taken);
     int[,] help;
     if (m.Field[pos[0], pos[1]].Tok == "stone"){
         Token.PlayerColor c = m.Field[pos[0], pos[1]].Color;
         help = new Stone(c).nextStep(m, pos);//field of information where you can move, or have to move a stone
     }
     else{
         Token.PlayerColor c = m.Field[pos[0], pos[1]].Color;
         help = new Draught(c).nextStep(m, pos);//field of information where you can move, or have to move a draught
     }
     return new int[]{-1,-1};
 }
コード例 #3
0
ファイル: World.cs プロジェクト: CedricHanebaum/Dame
        public World(int priority, int size, Draught.Control control, Map map)
            : base(priority)
        {
            this.control = control;
            this.map = map;
            map.addListener(this);

            tokens = new Token[size, size];
            board = new Board3D(boardBase, size);

            atMouse = Token.empty;
            atMousePos[0] = -1;
            atMousePos[1] = -1;

            this.refresh();
        }
コード例 #4
0
ファイル: Control.cs プロジェクト: CedricHanebaum/Dame
 public Control(Map m, Intelligence p1, Intelligence p2, Loop l)
 {
     this.m = m;
     this.l = l;
     l.addToUpdateList(this);
     if (!isHuman(p1) || !isHuman(p2))
     {
         AI = new RandomAI();
     }
     p1.Color = Intelligence.eColor.black;
     pList.Add(p1);
     p2.Color = Intelligence.eColor.white;
     pList.Add(p2);
     act = pList.ElementAt(0);
     AINext(null);
 }
コード例 #5
0
ファイル: Human.cs プロジェクト: CedricHanebaum/Dame
 public int[] ChooseToken(Map m, Token.PlayerColor color, List<int[]> taken)
 {
     return new int[]{-1,-1}; //TODO aus der GUI die gewählte Figur des Spielers holen
 }
コード例 #6
0
ファイル: RandomAI.cs プロジェクト: CedricHanebaum/Dame
        //returns the field the Player wants to visit
        public int[] SetStep(Map m, Token.PlayerColor color, int[] pos, int check, Control contrl, List<int[]> taken)
        {
            int[,] help;
            Random r = new Random();
            int r1;
            List<int[]> priority = new List<int[]>();
            List<int[]> visitable = new List<int[]>();

            if (m.Field[pos[0], pos[1]].Tok == "stone")
            {
                Token.PlayerColor c = m.Field[pos[0], pos[1]].Color;
                help = new Stone(c).nextStep(m, pos);//field of information where you can move, or have to move a stone
            }
            else
            {
                Token.PlayerColor c = m.Field[pos[0], pos[1]].Color;
                help = new Draught(c).nextStep(m, pos);//field of information where you can move, or have to move a draught
            }

            for (int a = 0; a < help.GetLength(1); ++a)
            {
                for (int b = 0; b < help.GetLength(1); ++b)
                {
                    if (help[a, b] == 1) priority.Add(new int[] { a, b }); //builds a list of field with priority
                    if (help[a, b] == 0) visitable.Add(new int[] { a, b });//builds a list of field which are visitable
                }
            }
            int[] temp;
            Token[,] field = m.Field;
            if (priority.Count != 0)
            {//if there are fields with higher priority
                for(int i=0; i<priority.Count; i++)
                {
                    temp = new int[] { priority[i][0], priority[i][1] };
                    contrl.temp = new int[] { pos[0], pos[1], temp[0], temp[1] };
                    return temp;
                }
            }
            else
            {
                for(int i=0; i<visitable.Count; i++)
                {
                    temp = new int[] { visitable[i][0], visitable[i][1] };
                    if (!removeTokens(field, color, temp, m))
                    {
                        contrl.temp = new int[] { pos[0], pos[1], temp[0], temp[1] };
                        return temp;
                    }
                }
            }
            if (check < 80)
            {
                taken.Add(pos);
                return SetStep(m, color, ChooseToken(m, color, taken), check + 1, contrl, taken);
            }
            else
            {
                if (priority.Count != 0)
                {//if there are fields with higher priority
                    r1 = r.Next(0, priority.Count);
                    temp = new int[] { priority[r1][0], priority[r1][1] };//choose a random field
                }
                else
                {
                    r1 = r.Next(0, visitable.Count);
                    temp = new int[] { visitable[r1][0], visitable[r1][1] };//choose a random field
                }
                contrl.temp = new int[] { pos[0], pos[1], temp[0], temp[1] };
                return temp;
            }
        }
コード例 #7
0
ファイル: RandomAI.cs プロジェクト: CedricHanebaum/Dame
 public bool removeTokens(Token[,] field, Token.PlayerColor color, int [] pos, Map m)
 {
     Token temp = null;
     int[] posN;
     for (int j = 0; j < field.GetLength(0); j++)
     {
         for (int k = 0; k < field.GetLength(1); k++)
         {
             if (field[j, k] == null)
                 continue;
             else if (field[j, k].Color != color)
             {
                 temp = field[j, k];
                 posN = new int[]{ j, k };
                 int[,] possible = temp.nextStep(m, posN);
                 for (int l = 0; l < possible.GetLength(0); l++)
                 {
                     for (int n = 0; n < possible.GetLength(1); n++)
                     {
                         if (possible[l, n] > -1)
                         {
                             if (isInDistance(posN, new int[] { l, n }, pos))
                             {
                                 return true;
                             }
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
コード例 #8
0
ファイル: RandomAI.cs プロジェクト: CedricHanebaum/Dame
 public int[] ChooseToken(Map m, Token.PlayerColor color, List<int[]> taken)
 {
     List<int[]> tokens = new List<int[]>();
     List<int[]> priorityTokens = new List<int[]>();
     List<int[]> prioOutOfway = new List<int[]>();
     Random r = new Random();
     int[,] compare = new int[m.Field.GetLength(1), m.Field.GetLength(1)];
     for (int i = 0; i < m.Field.GetLength(1); i++){//build a list off all tokens with a specific color
         for (int j = 0; j < m.Field.GetLength(1); j++)
         {
             if (m.Field[i, j] != null && m.Field[i, j].Color == color){
                 int[,] tmp = m.getToken(new int[] { i, j }).nextStep(m, new int[] { i, j });
                 bool moveable = false;
                 for (int a = 0; a < tmp.GetLength(1); a++){
                     for (int b = 0; b < tmp.GetLength(1); b++){
                         if (tmp[a, b] != -1)
                         {//if any turns are possible
                             moveable = true;
                         }
                     }
                 }
                 if (moveable == true)
                 {
                     tokens.Add(new int[] { i, j });
                 }
             }
         }
     }
     int count = 0;
     List<int> deleteList = new List<int>();
     for (int n = 0; n < tokens.Count; ++n)
     { //checks if there are any priority turns
         int[,] help = m.Field[tokens[n][0], tokens[n][1]].nextStep(m, new int[] { tokens[n][0], tokens[n][1] });
         for (int a = 0; a < help.GetLength(1); ++a)
         {
             for (int b = 0; b < help.GetLength(1); ++b)
             {
                 int iil = isInList(new int[] { tokens[n][0], tokens[n][1] }, taken, tokens);
                 if (help[a, b] == 1)
                 {
                     count++;
                     priorityTokens.Add(new int[] { tokens[n][0], tokens[n][1] });
                 }
                 else if (iil > -1 && tokens.Count > 1)
                     deleteList.Add(iil);
             }
         }
     }
     if (count == 0)
     {//there are no priority turns
         for (int i = 0; i < tokens.Count; ++i)//if AI can get a Draugt it should get it
         {
             if (deleteList.Contains(i))
             {
                 continue;
             }
             if (color == Token.PlayerColor.Black &&tokens[i][1] == m.Field.GetLength(1)-2&&m.Field[tokens[i][0],tokens[i][1]].Tok=="stone")
                 return new int[] { tokens[i][0], tokens[i][1] };
             if (color == Token.PlayerColor.White && tokens[i][1] == 1 && m.Field[tokens[i][0], tokens[i][1]].Tok == "stone")
                 return new int[] { tokens[i][0], tokens[i][1] };
         }
         int r1 = r.Next(0, tokens.Count);
         return new int[] { tokens[r1][0], tokens[r1][1] };
     }
     else
     {//there are priority turns
         for (int i = 0; i < priorityTokens.Count; ++i)
         {
             if (color == Token.PlayerColor.Black && priorityTokens[i][1] == m.Field.GetLength(1) - 3 && m.Field[tokens[i][0], tokens[i][1]].Tok == "stone")
                 return new int[] { priorityTokens[i][0], priorityTokens[i][1] };
             else if (color == Token.PlayerColor.White && priorityTokens[i][1] == 2 && m.Field[tokens[i][0], tokens[i][1]].Tok == "stone")
                 return new int[] { priorityTokens[i][0], priorityTokens[i][1] };
         }
         int r1 = r.Next(0, priorityTokens.Count);
         return new int[] { priorityTokens[r1][0], priorityTokens[r1][1] };
     }
 }
コード例 #9
0
ファイル: Token.cs プロジェクト: CedricHanebaum/Dame
 public abstract int[,] nextStep(Map field, int[] position);
コード例 #10
0
ファイル: Loop.cs プロジェクト: CedricHanebaum/Dame
 internal void startGame(int size, Draught.Intelligence p1, Draught.Intelligence p2)
 {
     map = new Map(size);
     control = new Draught.Control(map, p1, p2, this);
     world = new World(1, size, control, map);
     world.setVisible(true);
     drawManager.addDrawable(world);
     f.registerMouseListener(world);
     guiManager.closeActiveGui();
 }
コード例 #11
0
ファイル: Draught.cs プロジェクト: CedricHanebaum/Dame
 /*
  * 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;
 }
コード例 #12
0
ファイル: Draught.cs プロジェクト: CedricHanebaum/Dame
        /*
         * returns an Array with -1(field where u cannot go),0(field where you can go) and 1(priority move for jump)
         * gets the playing map , and the position of selected draugt
         */
        public override int[,] nextStep(Map field, int[] position)
        {
            List<int> erg0 = new List<int>();
            List<int> erg1 = new List<int>();
            List<int> erg2 = new List<int>();
            List<int> erg3 = new List<int>();
            int k = 1;
            int pos0 = position[0];     // x-coordinate of Draught
            int pos1 = position[1];     // y-coordinate of Draught
            int[,] map = new int[field.Field.GetLength(1), field.Field.GetLength(1)]; // integer-field to return with all viable moves

            for(int a=0;a<map.GetLength(1);++a)      // -1 for a field, where you cannot move forward to
            {
                for (int b=0;b<map.GetLength(1);++b)
                {
                    map[a, b] = -1;
                }
            }
            for (int i = 0; i < 4; ++i)// look in all diagonal directions from this draught where you can go
            {
                switch (i)
                {
                    case 0://diagonal up-left
                        {
                            erg0 = BotrightToTopleft(pos0, pos1, field, -k);
                            for (int j = 1; j <= erg0.Count; ++j)
                            {
                                if(pos0 - j >= 0 && pos1 - j >= 0)
                                map[pos0 - j, pos1 - j] = erg0[j-1];
                            }
                        }
                        break;
                    case 1://diagonal up-right
                        {
                            erg1 = BotleftToTopright(pos0, pos1, field, k);
                            for (int j = 1; j <= erg1.Count; ++j)
                            {
                                if(pos0 + j < map.GetLength(0) && pos1 - j >=0)
                                map[pos0 + j, pos1 - j] = erg1[j-1];
                            }
                            break;
                        }
                    case 2://diagonal bottom-right
                        {
                            erg2 = BotrightToTopleft(pos0, pos1, field, k);
                            for (int j = 1; j <= erg2.Count; ++j)
                            {
                                if(pos0 + j < map.GetLength(1) && pos1 + j < map.GetLength(1))
                                map[pos0 + j, pos1 + j] = erg2[j-1];
                            }
                            break;
                        }
                    case 3://diagonal bottom-left
                        {
                            erg3 = BotleftToTopright(pos0, pos1, field, -k);
                            for (int j = 1; j <= erg3.Count; ++j)
                            {
                                if(pos0-j >=0 && pos1+j < map.GetLength(1) )
                                map[pos0 - j, pos1 + j] = erg3[j-1];
                            }
                            break;
                        }
                    default: break;
                }
            }
            return map;
        }