public ZertzRingRenderer RemoveRing(HexLocation loc) { ZertzRingRenderer zrr = rings[loc.X,loc.Y]; ringlocs.Remove(zrr); rings[loc.X,loc.Y] = null; return zrr; }
public ZertzBallRenderer RemoveBall(HexLocation loc) { ZertzBallRenderer zbr = balls[loc.X,loc.Y]; balllocs.Remove(zbr); balls[loc.X,loc.Y] = null; return zbr; }
private void perform_CaptureBall(HexLocation loc, ZertzBallContainerType zbct) { lock(this.handlers) { foreach(IZertzActionHandler izah in this.handlers) { izah.CaptureBall(loc,zbct); } } }
public ZertzGame(out HexLocation[] hls) { //this.players = new IPlayer[] {playerA,playerB}; this.board = ZertzBoard.OffsetBoard(out hls); this.playersPools = new ZertzBallContainer[] {ZertzBallContainer.Empty(),ZertzBallContainer.Empty()}; this.turn = 0x00; this.zmc = new ZertzMoveCreator(this); }
public ZertzRingRenderer(ZertzGame game, HexLocation hexLocation, Vector3 tileVector, Vector3 tileEscape, float time) { register(); this.tt = new Vector3((float) UniversalRandom.NextDouble(),(float) UniversalRandom.NextDouble(),0.0f); this.hexLocation = hexLocation; this.boardLocation = Maths.HexVector(hexLocation,2.0f*OUTER_RADIUS+SPACING,0.5f*THICKNESS); this.tileVector = tileVector; this.RenderMover = RenderMoveManager.GenerateWaitMover(time,this.tileVector,RenderMoveManager.GenerateMoveMover(this.tileVector,tileEscape,2.0f,RenderMoveManager.GenerateHopMover(tileEscape,this.boardLocation,1.5f,null))); //this.RenderMover = RenderMoveManager.GenerateStaticMover(this.tileVector); }
public void TestConstructor() { HexLocation zl; for(sbyte x = sbyte.MinValue; x < sbyte.MaxValue; x++) { for(sbyte y = sbyte.MinValue; y < sbyte.MaxValue; y++) { zl = new HexLocation(x,y); Assert.AreEqual(x,zl.X); Assert.AreEqual(y,zl.Y); } } }
public void TestShiftOperator() { for(int i = 0x00; i < 0x08; i++) { sbyte bm = (sbyte) (sbyte.MinValue>>i); sbyte bM = (sbyte) (sbyte.MaxValue>>i); for(sbyte b = bm; b < bM; b++) { for(sbyte c = bm; c < bM; c++) { HexLocation hl = new HexLocation(b,c)<<i; Assert.AreEqual(b<<i,hl.X); Assert.AreEqual(c<<i,hl.Y); } } } }
public override ZertzMoveState CaptureLand(HexLocation location) { //GUARDS if (!this.Board.CanCapture(location)) { throw new InvalidZertzActionException("Unable to do this action: This land cannot be captured!"); } //ACTIONS this.Game.PutToPool(this.Board.CaptureLandPieces(location)); //EVENTS this.Creator.perform_ChangeState(0x05); //NEXT_STATE return(new CaptureLandZertzMoveState(this.Creator)); }
public override BehaviourResult Clicked(RayMeshGeometry3DHitTestResult rayMeshResult, BoardVisual board) { HexVisual hexVisual = rayMeshResult.VisualHit as HexVisual; if (hexVisual != null) { ResourceHex resourceHex = hexVisual.Hex as ResourceHex; if (resourceHex != null) { _Location = resourceHex.Location; return BehaviourResult.Success; } } return BehaviourResult.NoSuccess; }
public void TestConstructor() { HexLocation zl; for (sbyte x = sbyte.MinValue; x < sbyte.MaxValue; x++) { for (sbyte y = sbyte.MinValue; y < sbyte.MaxValue; y++) { zl = new HexLocation(x, y); Assert.AreEqual(x, zl.X); Assert.AreEqual(y, zl.Y); } } }
public override ZertzMoveState SelectPiece(HexLocation location) { //GUARDS if (!this.Board.IsFree(location)) { throw new InvalidZertzActionException("Unable to do this action: This piece can't be removed!"); } //ACTIONS this.Board.RemoveZertzPiece(location); //EVENT this.Creator.perform_RemovePiece(location); this.Creator.perform_ChangeState(0x05); //NEXT_STATE return(new CaptureLandZertzMoveState(this.Creator)); }
public override ZertzMoveState SelectPiece(HexLocation location) { //GUARDS if (!this.Board.IsVacant(location)) { throw new InvalidZertzActionException("Unable to do this action: ball must be put on a vacant piece!"); } //ACTIONS this.Board.PutZertzBall(location, this.Ball); //EVENT this.Creator.perform_PutBall(this.source, this.ball, location); this.Creator.perform_ChangeState(0x03); //NEXT_STATE return(new PlacRem2ZertzMoveState(this.Creator)); }
public void TestShiftOperator() { for (int i = 0x00; i < 0x08; i++) { sbyte bm = (sbyte)(sbyte.MinValue >> i); sbyte bM = (sbyte)(sbyte.MaxValue >> i); for (sbyte b = bm; b < bM; b++) { for (sbyte c = bm; c < bM; c++) { HexLocation hl = new HexLocation(b, c) << i; Assert.AreEqual(b << i, hl.X); Assert.AreEqual(c << i, hl.Y); } } } }
private HexLocation[] generateAllLocations() { HexLocation[] hls = new HexLocation[0x25]; int k = 0x00; sbyte j, o1, o2; for (sbyte i = 0x00; i <= 0x06; i++) { o1 = (sbyte)Math.Max(0x00, 0x03 - i); o2 = (sbyte)Math.Min(0x06, 0x09 - i); for (j = o1; j <= o2; j++) { hls[k++] = new HexLocation(i, j); } } return(hls); }
private void innerTestIsVacant(ZertzBoard board, HexLocation[] vacant) { HashSet <HexLocation> hls = new HashSet <HexLocation>(); foreach (HexLocation l in vacant) { hls.Add(l); } HexLocation hl; for (sbyte i = 0x00; i < 0x07; i++) { for (sbyte j = 0x00; j < 0x07; j++) { hl = new HexLocation(i, j); Assert.AreEqual(hls.Contains(hl), board.IsVacant(hl)); } } }
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)); }
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); }
public ZertzPiece this [HexLocation zl] { get { if (zl.X < 0x00 || zl.Y < 0x00 || zl.X >= this.pieces.GetLength(0x00) || zl.Y >= this.pieces.GetLength(0x01)) { return(ZertzPiece.Dead); } else { return(this.pieces[zl.X, zl.Y]); } } internal set { if (zl.X < 0x00 || zl.Y < 0x00 || zl.X >= this.pieces.GetLength(0x00) || zl.Y >= this.pieces.GetLength(0x01)) { throw new InvalidZertzActionException("Unable to set a piece out of range!"); } else { this.pieces[zl.X, zl.Y] = value; } } }
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); }
public void TestOperators() { HexLocation hla = new HexLocation(0, 0); HexLocation hlb = new HexLocation(1, 0); HexLocation hlc = new HexLocation(-1, 0); HexLocation hld = new HexLocation(0, 1); HexLocation hle = new HexLocation(0, -1); HexLocation hlf = new HexLocation(1, -1); HexLocation hlg = new HexLocation(-1, 1); HexLocation hlh = new HexLocation(2, 0); HexLocation hli = new HexLocation(2, 1); HexLocation hlj = new HexLocation(2, 2); HexLocation hlk = new HexLocation(1, 3); HexLocation hll = new HexLocation(0, 4); HexLocation hlm = new HexLocation(-4, 4); Assert.AreEqual(hlb, hlb - hla); Assert.AreEqual(hlc, hlc - hla); Assert.AreEqual(hld, hld - hla); Assert.AreEqual(hle, hle - hla); Assert.AreEqual(hlf, hlf - hla); Assert.AreEqual(hlg, hlg - hla); Assert.AreEqual(hlh, hlh - hla); Assert.AreEqual(hlb, hlb + hla); Assert.AreEqual(hlc, hlc + hla); Assert.AreEqual(hld, hld + hla); Assert.AreEqual(hle, hle + hla); Assert.AreEqual(hlf, hlf + hla); Assert.AreEqual(hlg, hlg + hla); Assert.AreEqual(hlh, hlh + hla); Assert.AreEqual(hlb, !hlh); Assert.AreEqual(HexLocation.Invalid, !hli); Assert.AreEqual(HexLocation.Invalid, !hlj); Assert.AreEqual(HexLocation.Invalid, !hlk); Assert.AreEqual(hld, !hll); Assert.AreEqual(hlg, !hlm); }
public override ZertzMoveState SelectPiece(HexLocation location) { HexLocation dir = !(location - this.HopLocation); //GUARDS if (dir == HexLocation.Invalid) { throw new InvalidZertzActionException("Unable to perform this action: No direction specified!"); } else if (!this.Board.CanHop(this.HopLocation, dir.HexDirection)) { throw new InvalidZertzActionException("Unable to perform this action: Can't hop in the given direction!"); } //ACTIONS this.Game.PutToPool(this.Board.DoHopMove(this.HopLocation, dir.HexDirection)); //EVENTS this.Creator.perform_ChangeState(0x04); this.Creator.perform_PerformHop(hopLocation, location); //TODO: insert capture action //NEXT_STATE HexLocation newl = this.HopLocation + (dir << 0x01); return(new Capture2ZertzMoveState(this.Creator, newl)); }
public void TestOperators() { HexLocation hla = new HexLocation(0,0); HexLocation hlb = new HexLocation(1,0); HexLocation hlc = new HexLocation(-1,0); HexLocation hld = new HexLocation(0,1); HexLocation hle = new HexLocation(0,-1); HexLocation hlf = new HexLocation(1,-1); HexLocation hlg = new HexLocation(-1,1); HexLocation hlh = new HexLocation(2,0); HexLocation hli = new HexLocation(2,1); HexLocation hlj = new HexLocation(2,2); HexLocation hlk = new HexLocation(1,3); HexLocation hll = new HexLocation(0,4); HexLocation hlm = new HexLocation(-4,4); Assert.AreEqual(hlb,hlb-hla); Assert.AreEqual(hlc,hlc-hla); Assert.AreEqual(hld,hld-hla); Assert.AreEqual(hle,hle-hla); Assert.AreEqual(hlf,hlf-hla); Assert.AreEqual(hlg,hlg-hla); Assert.AreEqual(hlh,hlh-hla); Assert.AreEqual(hlb,hlb+hla); Assert.AreEqual(hlc,hlc+hla); Assert.AreEqual(hld,hld+hla); Assert.AreEqual(hle,hle+hla); Assert.AreEqual(hlf,hlf+hla); Assert.AreEqual(hlg,hlg+hla); Assert.AreEqual(hlh,hlh+hla); Assert.AreEqual(hlb,!hlh); Assert.AreEqual(HexLocation.Invalid,!hli); Assert.AreEqual(HexLocation.Invalid,!hlj); Assert.AreEqual(HexLocation.Invalid,!hlk); Assert.AreEqual(hld,!hll); Assert.AreEqual(hlg,!hlm); }
public ZertzBallContainer CaptureLandPieces(HexLocation hl) { //CLP HashSet<HexLocation> visited = new HashSet<HexLocation>(); Stack<HexLocation> todo = new Stack<HexLocation>(); ZertzBallContainer zbc = ZertzBallContainer.Empty(); ZertzPiece zp; zbc[this[hl].BallType]++; this[hl] = ZertzPiece.Dead; 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]; if(!visited.Contains(nei)) { visited.Add(nei); zp = this[nei]; if(zp.IsAlive) { zbc[zp.BallType]++; this[nei] = ZertzPiece.Dead; todo.Push(nei); } } } } return zbc; }
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; }
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); }
public virtual ZertzMoveState CaptureLand(HexLocation location) { //CL return NotPossible(); }
public override ZertzMoveState SelectPiece(HexLocation location) { //GUARDS if(!this.Board.CanHop(location)) { throw new InvalidZertzActionException("Unable to do this action: the ball can't hop!"); } //ACTIONS //EVENTS this.Creator.perform_ChangeState(0x02); //NEXT_STATE return new Capture1ZertzMoveState(this.Creator,location); }
private void BuildAndAssertResult(bool expectation, Action <TerraTile> beforeExecute = null, HexLocation location = null) { var loc = location ?? new HexLocation(1, 1); var tile = this.Board.TileForLocation(loc); Func <TerraMysticaAction> prepareAction = () => new BuildAction(this.Board, this.Player, loc); Action before = () => beforeExecute?.Invoke(tile); this.PerformActionAndAssertResult(expectation, prepareAction, before); }
public void RemoveZertzPiece(HexLocation hl) { //RZP this[hl] = ZertzPiece.Dead; }
public void TestBuild_TileAlreadyOwnedFailure() { var loc = new HexLocation(1, 1); this.BuildAndAssertFailure(tile => this.Board.TileForLocation(loc).Owner = new TestPlayer(), loc); }
private void BuildAndAssertFailure(Action <TerraTile> beforeExecute = null, HexLocation location = null) { this.BuildAndAssertResult(false, beforeExecute, location); }
public PutBallRemovePieceZertzMove(HexLocation put, ZertzBallType ball, HexLocation rem) { }
public CaptureZertzMoveState(ZertzMoveCreator creator, HexLocation hopLocation) : base(creator) { this.hopLocation = hopLocation; }
private void perform_PutBall(ZertzBallContainerType containertype, ZertzBallType type, HexLocation location) { lock (this.handlers) { foreach (IZertzActionHandler izah in this.handlers) { izah.PutBall(containertype, type, location); } } }
public bool HasNeighbours(HexLocation zl) { foreach(HexLocation dir in HexLocation.NeighbourDirections) { if(this[zl+dir].IsAlive) { return true; } } return false; }
public override ZertzMoveState CaptureLand(HexLocation location) { //GUARDS if(this.Board.HasFree()) { throw new InvalidZertzActionException("Unable to do this action: An free piece must first be removed!"); } if(!this.Board.CanCapture(location)) { throw new InvalidZertzActionException("Unable to do this action: This land cannot be captured!"); } //ACTIONS this.Game.PutToPool(this.Board.CaptureLandPieces(location)); //EVENTS this.Creator.perform_ChangeState(0x05); //TODO: insert event //NEXT_STATE return new CaptureLandZertzMoveState(this.Creator); }
public bool IsVacant(HexLocation hl) { //IV return this[hl].IsVacant; }
public void CaptureLand(HexLocation location) { this.setState(state.CaptureLand(location)); }
public Capture2ZertzMoveState(ZertzMoveCreator creator, HexLocation hopLocation) : base(creator, hopLocation) { }
public virtual ZertzMoveState CaptureLand(HexLocation location) //CL { return(NotPossible()); }
public override ZertzMoveState SelectPiece(HexLocation location) { //GUARDS if(!this.Board.IsFree(location)) { throw new InvalidZertzActionException("Unable to do this action: This piece can't be removed!"); } //ACTIONS this.Board.RemoveZertzPiece(location); //EVENT this.Creator.perform_RemovePiece(location); this.Creator.perform_ChangeState(0x05); //NEXT_STATE return new CaptureLandZertzMoveState(this.Creator); }
public virtual ZertzMoveState SelectPiece(HexLocation location) //SP { return(NotPossible()); }
public void SelectPiece(HexLocation location) { this.setState(state.SelectPiece(location)); }
public void CaptureBall(HexLocation location, ZertzBallContainerType type) { }
public virtual ZertzMoveState SelectPiece(HexLocation location) { //SP return NotPossible(); }
public void SelectPiece(HexLocation location) { this.zmc.SelectPiece(location); }
private void perform_PerformHop(HexLocation fr, HexLocation to) { lock(this.handlers) { foreach(IZertzActionHandler izah in this.handlers) { izah.PerformHop(fr,to); } } }
public void CaptureLand(HexLocation location) { this.zmc.CaptureLand(location); }
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; }
public void PutBall(ZertzBallContainerType containertype, ZertzBallType type, HexLocation location) { ZertzContainerRenderer zbcr = this.zcr[containertype]; ZertzBallRenderer zbr = zbcr.GetBallOfType(type); zbcr.Remove(zbr); this.boardR.PutBall(zbr, location); zbr.RenderMover = RenderMoveManager.GenerateHopMover(zbr.Location, Maths.HexVector(location, 2.0f * ZertzRingRenderer.OUTER_RADIUS + ZertzRingRenderer.SPACING, 0.5f * ZertzRingRenderer.THICKNESS), 1.5f, null); }
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; }
public CaptureZertzMove(HexLocation offset, params HexDirection[] hops) { this.offset = offset; this.hops = hops; }
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)); }
public ZertzRingRenderer GetRingAt(HexLocation loc) { return(this.rings[loc.X, loc.Y]); }
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; }
public void PutZertzBall(HexLocation hl, ZertzBallType type) { //PZB ZertzPiece piece = ZertzPiece.Vacant; piece.PutBall(type); this[hl] = piece; }
public override ZertzMoveState SelectPiece(HexLocation location) { //GUARDS if(!this.Board.IsVacant(location)) { throw new InvalidZertzActionException("Unable to do this action: ball must be put on a vacant piece!"); } //ACTIONS this.Board.PutZertzBall(location,this.Ball); //EVENT this.Creator.perform_PutBall(this.source,this.ball,location); this.Creator.perform_ChangeState(0x03); //NEXT_STATE return new PlacRem2ZertzMoveState(this.Creator); }
public ZertzPiece this[HexLocation zl] { get { if(zl.X < 0x00 || zl.Y < 0x00 || zl.X >= this.pieces.GetLength(0x00) || zl.Y >= this.pieces.GetLength(0x01)) { return ZertzPiece.Dead; } else { return this.pieces[zl.X,zl.Y]; } } internal set { if(zl.X < 0x00 || zl.Y < 0x00 || zl.X >= this.pieces.GetLength(0x00) || zl.Y >= this.pieces.GetLength(0x01)) { throw new InvalidZertzActionException("Unable to set a piece out of range!"); } else { this.pieces[zl.X,zl.Y] = value; } } }