Beispiel #1
0
        public void PutZertzBall(HexLocation hl, ZertzBallType type)           //PZB
        {
            ZertzPiece piece = ZertzPiece.Vacant;

            piece.PutBall(type);
            this[hl] = piece;
        }
Beispiel #2
0
        private ZertzBoard buildSampleBoard2()
        {
            HexLocation[] hls;
            ZertzBoard    board = ZertzBoard.OffsetBoard(out hls);
            ZertzPiece    dead  = ZertzPiece.Dead;
            ZertzPiece    blac  = ZertzPiece.Vacant;

            blac.PutBall(ZertzBallType.Black);
            ZertzPiece gray = ZertzPiece.Vacant;

            gray.PutBall(ZertzBallType.Gray);
            ZertzPiece whit = ZertzPiece.Vacant;

            whit.PutBall(ZertzBallType.White);
            board[0x00, 0x03] = dead;
            board[0x00, 0x06] = dead;
            board[0x01, 0x06] = dead;
            board[0x02, 0x06] = dead;
            board[0x03, 0x06] = dead;
            board[0x05, 0x02] = dead;
            board[0x06, 0x02] = dead;
            board[0x06, 0x01] = dead;
            board[0x03, 0x05] = dead;
            board[0x04, 0x05] = dead;
            board[0x04, 0x04] = dead;
            board[0x05, 0x04] = dead;
            board[0x05, 0x03] = dead;
            board[0x06, 0x03] = dead;
            board[0x01, 0x03] = whit;
            board[0x02, 0x04] = whit;
            board[0x02, 0x03] = gray;
            board[0x05, 0x00] = gray;
            board[0x03, 0x01] = blac;
            return(board);
        }
Beispiel #3
0
        public static ZertzBoard OffsetBoard(out HexLocation[] hls)
        {
            ZertzPiece[,] pieces = new ZertzPiece[0x07, 0x07];
            hls = new HexLocation[0x25];
            int o1, o2, j, k = 0x00;

            for (int i = 0x00; i <= 0x06; i++)
            {
                o1 = Math.Max(0x00, 0x03 - i);
                o2 = Math.Min(0x06, 0x09 - i);
                for (j = 0x00; j < o1; j++)
                {
                    pieces[i, j] = ZertzPiece.Dead;
                }
                for (; j <= o2; j++)
                {
                    pieces[i, j] = ZertzPiece.Vacant;
                    hls[k++]     = new HexLocation((sbyte)i, (sbyte)j);
                }
                for (; j <= 0x06; j++)
                {
                    pieces[i, j] = ZertzPiece.Dead;
                }
            }
            return(new ZertzBoard(pieces));
        }
Beispiel #4
0
        public bool CanHop(HexLocation hl)           //CH2
        {
            ZertzPiece zp = this[hl];

            if (!zp.IsAlive || !zp.ContainsBall)
            {
                return(false);
            }
            HexLocation zla, dir;

            for (int i = 0x00; i < 0x06; i++)
            {
                dir = HexLocation.NeighbourDirections[i];
                zla = hl + dir;
                zp  = this[zla];
                if (zp.IsAlive && zp.ContainsBall)
                {
                    zla += dir;
                    zp   = this[zla];
                    if (zp.IsAlive && !zp.ContainsBall)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #5
0
 private ZertzBoard(ZertzPiece[,] pieces)
 {
     this.pieces = pieces;
     int wo = (int) Math.Ceiling(2.0f*vr_m+2.0f*7.0f*vr_R+6.0f*vr_s);
     int ho = (int) Math.Ceiling(2.0f*vr_m+2.0f*vr_R+(2.0f*6.0f*vr_R+6.0f*vr_s)*Maths.Sqrt3_4);
     int w = Maths.ToNextPow2(wo);
     int h = Maths.ToNextPow2(ho);
     float wr = (float) wo/w;
     float hr = (float) ho/h;
     this.visualFactor = (float) wo/ho;
     this.textureBounds = new RectangleF(0.5f-0.5f*wr,0.5f-0.5f*hr,wr,hr);
     this.visual = new Bitmap(w,h);
     this.Repaint();
 }
Beispiel #6
0
        private ZertzBoard buildSampleBoard9()
        {
            HexLocation[] hls;
            ZertzBoard    board = ZertzBoard.OffsetBoard(out hls);
            ZertzPiece    blac  = ZertzPiece.Vacant;

            blac.PutBall(ZertzBallType.Black);
            for (int i = 0x00; i < 0x07; i++)
            {
                for (int j = 0x00; j < 0x07; j++)
                {
                    if (board[i, j].IsAlive)
                    {
                        board[i, j] = blac;
                    }
                }
            }
            return(board);
        }
Beispiel #7
0
        public ZertzBallType DoHopMove(HexLocation zl, HexDirection dir)
        {
            HexLocation hldir = HexLocation.NeighbourDirections[(byte)dir];
            HexLocation zla = zl, zlb = zla + hldir, zlc = zlb + hldir;
            //if(this[zla].CanDropBall() && this[zlb].CanDropBall() && this[zlc].CanPutBall()) {
            ZertzPiece zpa = this[zla];
            ZertzPiece zpb = this[zlb];
            ZertzPiece zpc = this[zlc];

            zpc.PutBall(zpa.DropBall());
            ZertzBallType t = zpb.DropBall();

            this[zla] = zpa;
            this[zlb] = zpb;
            this[zlc] = zpc;
            return(t);
            //}
            //throw new InvalidZertzActionException(String.Format("Can't perform this hop operation: [{0}:{1}]",zl,dir));
        }
Beispiel #8
0
        public bool IsFree(HexLocation hl)           //IF
        {
            ZertzPiece zp = this[hl];

            if (zp.IsAlive && !zp.ContainsBall)
            {
                HexLocation zla, zlb;
                zlb = HexLocation.NeighbourDirections[0x05] + hl;
                for (int i = 0x00; i < 0x06; i++)
                {
                    zla = zlb;
                    zlb = HexLocation.NeighbourDirections[i];
                    if (!this[zla].IsAlive && !this[hl + zlb].IsAlive && !this[zla + zlb].IsAlive)
                    {
                        return(true);
                    }
                    zlb += hl;
                }
            }
            return(false);
        }
Beispiel #9
0
        public bool CanHop(HexLocation zl, HexDirection dir)           //CH3
        {
            HexLocation zla   = zl;
            ZertzPiece  zp    = this[zla];
            HexLocation hldir = HexLocation.NeighbourDirections[(byte)dir];

            if (zp.IsAlive && zp.ContainsBall)
            {
                zla += hldir;
                zp   = this[zla];
                if (zp.IsAlive && zp.ContainsBall)
                {
                    zla += hldir;
                    zp   = this[zla];
                    if (zp.IsAlive && !zp.ContainsBall)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #10
0
 public static ZertzBoard OffsetBoard(out HexLocation[] hls)
 {
     ZertzPiece[,] pieces = new ZertzPiece[0x07,0x07];
     hls = new HexLocation[0x25];
     int o1, o2, j, k = 0x00;
     for(int i = 0x00; i <= 0x06; i++) {
         o1 = Math.Max(0x00,0x03-i);
         o2 = Math.Min(0x06,0x09-i);
         for(j = 0x00; j < o1; j++) {
             pieces[i,j] = ZertzPiece.Dead;
         }
         for(; j <= o2; j++) {
             pieces[i,j] = ZertzPiece.Vacant;
             hls[k++] = new HexLocation((sbyte) i,(sbyte) j);
         }
         for(; j <= 0x06; j++) {
             pieces[i,j] = ZertzPiece.Dead;
         }
     }
     return new ZertzBoard(pieces);
 }
Beispiel #11
0
        public bool CanCapture(HexLocation hl)
        {
            ZertzPiece zp = this[hl];

            if (!zp.IsAlive || !zp.ContainsBall)
            {
                return(false);
            }
            HashSet <HexLocation> visited = new HashSet <HexLocation>();
            Stack <HexLocation>   todo    = new Stack <HexLocation>();

            visited.Add(hl);
            todo.Push(hl);
            HexLocation hla, nei;

            while (todo.Count > 0x00)
            {
                hla = todo.Pop();
                for (int i = 0x00; i < 0x06; i++)
                {
                    nei = hla + HexLocation.NeighbourDirections[i];
                    zp  = this[nei];
                    if (zp.IsAlive)
                    {
                        if (zp.ContainsBall)
                        {
                            if (!visited.Contains(nei))
                            {
                                visited.Add(nei);
                                todo.Push(nei);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            int  nIsland = visited.Count;
            int  nCurrent;
            int  m      = this.pieces.GetLength(0x00);
            int  n      = this.pieces.GetLength(0x01);
            bool unique = true;

            //not the main part (or it is the only island!)
            for (sbyte i = 0x00; i < m; i++)
            {
                for (sbyte j = 0x00; j < n; j++)
                {
                    hla = new HexLocation(i, j);
                    zp  = this[hla];
                    if (zp.IsAlive && !visited.Contains(hla))
                    {
                        //we discovered a new island
                        unique   = false;
                        nCurrent = 0x01;
                        visited.Add(hla);
                        todo.Push(hla);
                        while (todo.Count > 0x00)
                        {
                            hla = todo.Pop();
                            for (int k = 0x00; k < 0x06; k++)
                            {
                                nei = hla + HexLocation.NeighbourDirections[k];
                                zp  = this[nei];
                                if (zp.IsAlive)
                                {
                                    if (!visited.Contains(nei))
                                    {
                                        visited.Add(nei);
                                        todo.Push(nei);
                                        nCurrent++;
                                        if (nCurrent >= nIsland)
                                        {
                                            return(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(unique);
        }