public void MoveCreatureTest() { MapCreator creator = new MapCreator(); IMap map = creator.GenerateFlatMap(2, 2, new Dictionary <TileValues, int> { { TileValues.Forest, 1 } }); CreatureGenerator generator = new CreatureGenerator(); ICreature creature = generator.GenerateCreature(CreatureTypes.Human); ITile currentTile = map.Tiles[0]; ITile newTile = map.Tiles[1]; currentTile.CreatureList.Add(creature); MoveCreatureActionParameter parameter = new MoveCreatureActionParameter() { Creature = creature, CurrentCreatureTile = currentTile, NewCreatureTile = newTile, }; MoveCreatureAction action = new MoveCreatureAction(); IActionResult result = action.Execute(parameter); Assert.IsTrue(result.Success); Assert.AreEqual(0, currentTile.CreatureList.Count); Assert.AreEqual(1, newTile.CreatureList.Count); Assert.IsFalse(currentTile.CreatureList.Contains(creature)); Assert.IsTrue(newTile.CreatureList.Contains(creature)); }
public override void Visit(MoveCreatureAction action) { //Log("card moved to " + action.Place.ToString()); Player p = GameManager.GetPlayer(action.Caller); CreatureCard creature = p.MoveACreatureFromPlace(action.PlayedCardId, action.Place); foreach (CharacterEnum target in GameManager.UserDict.Keys.ToList()) { GameManager.UserDict[target].Write(new ResponseMessage(new MoveCreatureResponse(action.Caller, creature, action.Place, action.TablePos))); } }
/// <summary> /// Faster function to evaluate all the possible movements in the movement phase /// </summary> /// <param name="gm"></param> /// <returns> Best movement action</returns> private KeyValuePair <Double, PlayerAction> ThinkToMove(GameManager gm) { GameManager toUse = CreateGameManagerAndStuff(gm); Player me = toUse.UserDict[CharacterEnum.AMARU].Player; LimitedList <Card> myCards = me.Hand; LimitedList <CreatureCard> myWarZone = me.Outer; LimitedList <CreatureCard> myInnerZone = me.Inner; List <KeyValuePair <Double, PlayerAction> > listPossibleActions = new List <KeyValuePair <double, PlayerAction> >(); foreach (CreatureCard cd in myWarZone.Concat(myInnerZone)) { try { // Log("TESTO la carta "+ cd.Name + " in war zone? " + myWarZone.Contains(cd)); // Log(me.IsShieldMaidenProtected.ToString()); GameManager toUseTemp = CreateGameManagerAndStuff(toUse); MoveCreatureAction myIntention = new MoveCreatureAction(CharacterEnum.AMARU, cd.Id, (myInnerZone.Contains(cd) ? Place.OUTER : Place.INNER), 0); myIntention.Visit(toUseTemp.ValidationVisitor); myIntention.Visit(toUseTemp.ExecutionVisitor); Double valueOfGoal = ValueMyField(toUseTemp); listPossibleActions.Add(new KeyValuePair <Double, PlayerAction>(valueOfGoal, myIntention)); } catch (Exception e) { Log("Eccezione " + e.ToString()); Log(cd.Name); } } listPossibleActions = listPossibleActions.OrderByDescending(x => x.Key).ToList(); if (listPossibleActions.Count > 0) { Log(listPossibleActions[0].ToString()); return(listPossibleActions[0]); } else { return(new KeyValuePair <double, PlayerAction>(Double.MinValue, new EndTurnAction(CharacterEnum.AMARU, -1, false))); } }
public override void Visit(MoveCreatureAction action) { // Check caller player is alive and it is not its main turn Player caller = this.GameManager.GetPlayer(action.Caller); if (!caller.IsAlive || GameManager.ActiveCharacter != action.Caller || GameManager.IsMainTurn) { throw new CallerCannotPlayException(); } // Check card exists and is in proper position Place from; if (action.Place == Place.INNER) { from = Place.OUTER; } else if (action.Place == Place.OUTER) { from = Place.INNER; } else { throw new InvalidCardLocationException(); } if (caller.GetCardFromId(action.PlayedCardId, from) == null) { throw new CardNotAvailableException(); } // Check that target place has enough room if ((action.Place == Place.INNER && caller.Inner.Count >= AmaruConstants.INNER_MAX_SIZE) || (action.Place == Place.OUTER && caller.Outer.Count >= AmaruConstants.OUTER_MAX_SIZE)) { throw new TargetPlaceFullException(action.Place); } }