public void Create_FromState_InitializedField()
		{
			var state = new GameState()
			{
				Player2 = new GameState.Player()
				{
					Combo = 12,
					Points = 10,
					Field = new int[,] 
					{ 
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
						{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 0 },
						{ 0, 0, 0, 0, 0, 0, 0, 2, 2, 0 },
						{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
					},
				},
				Player1 = new GameState.Player()
				{
					Combo = 0,
					Points = 0,
					Field = new int[,]
					{
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
						{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 0 },
						{ 0, 0, 0, 0, 0, 0, 0, 2, 2, 0 },
						{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
					},
				},
			};
			var act = Field.Create(state, PlayerName.Player2);
			FieldAssert.AreEqual("..........|........X.|.......XX.", 10, 12, 0, act);
		}
		public static GameState Create(IEnumerable<IInstruction> instructions)
		{
			var state = new GameState();

			foreach(var instruction in instructions.Where(i => Mapping.ContainsKey(i.GetType())))
			{
				Mapping[instruction.GetType()].Invoke(instruction, state);
			}
			return state;
		}
Пример #3
0
		public static ushort Create(GameState state, PlayerName name, int r)
		{
			ushort row = 0;

			for (var c = 0; c < 10; c++)
			{
				if (state[name].Field[r, c] == FieldInstruction.FixedBlock)
				{
					row |= Flag[c];
				}
				else if (state[name].Field[r, c] == FieldInstruction.LockedBlock)
				{
					return Row.Locked;
				}
			}
			return row;
		}
		/// <summary>Runs it all.</summary>
		public void DoRun(IBot bot, IEnumerable<IInstruction> instructions)
		{
			if (bot == null) { throw new ArgumentNullException("bot"); }
			if (instructions == null) { throw new ArgumentNullException("instructions"); }

			var settings = new Settings();
			var state = new GameState();

			foreach (var instruction in instructions)
			{
				if (settings.Apply(instruction))
				{
					bot.ApplySettings(settings);
				}
				else if (state.Apply(instruction)) { }
				else if (instruction is RequestMoveInstruction)
				{
					bot.Update(state);
#if !DEBUG
					try
					{
#endif
						var response = bot.GetResponse(((RequestMoveInstruction)instruction).Time);
						Writer.WriteLine(response.Move);
						if (!String.IsNullOrEmpty(response.Log))
						{
							Logger.WriteLine(response.Log);
						}
#if !DEBUG
					}
					catch (Exception x)
					{
						Writer.WriteLine(MoveInstruction.NoMoves);
						Logger.WriteLine(x);
					}
#endif
				}
			}
		}
		public BenchmarkBot(Block current, Block next, int round)
			: base(new MT19937Generator(round))
		{
			State = new GameState()
			{
				Round = round,
			};
			c = current;
			n = next;
		}
		public void Update(GameState state)
		{
			State = state;
			Field = Field.Create(State, Settings.YourBot);
			Opponent = Field.Create(State, Settings.OppoBot);
		}