Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- using Evertop.Soccer.Common;
- using System.Collections.Generic;
- namespace SocLib_v1_1_2
- {
- class Zawodowiec : IPlayer
- {
- private Direction[] allDirections = new Direction[8];
- private FieldData Map;
- private int Side;
- public string Name
- {
- get
- {
- return "Cancer";
- }
- }
- private int ballSector(int x, int y, int length, int width)
- {
- if (y == 0) return 0; // górna krawędź
- if (y == 1 && x > 0 && x < length) return 1; // przy górnej krawędzi
- if (y == width) return 2; // dolna krawędź
- if (y == width - 1 && x > 0 && x < length) return 3; // przy dolnej krawędzi
- if (y == width / 2 && x == length / 2) return 4; // środek
- if(Side == 1)
- {
- if (x == 0 && y >= (width / 2) - 1 && y <= (width / 2) + 1) return 5; // bramka przeciwnika
- if (x == 0 && y < (width / 2) - 1) return 6; // nad bramką przeciwnika
- if (x == 0 && y > (width / 2) + 1) return 7; // pod bramką przeciwnika
- if (x == length && y == width / 2) return 8; // twoja bramka
- if (x == length && y == (width / 2) - 1) return 23; // górny słupek twojej bramki
- if (x == length && y == (width / 2) + 1) return 24; // dolny słupek twojej bramki
- if (x == length -1 && y == (width / 2) - 2) return 25; // górny słupek twojej bramki +1/1
- if (x == length -1 && y == (width / 2) + 2) return 26; // dolny słupek twojej bramki +1/1
- if (x == length && y < width / 2) return 9; // nad twoją bramką
- if (x == length && y > width / 2) return 10; // pod twoją bramką
- if (x == 1 && y == width / 2) return 11; // naprzeciwko bramki przeciwnika
- if (x == 1 && y == (width / 2) - 1) return 12; // naprzeciwko górnego słupka przeciwnika
- if (x == 1 && y == (width / 2) + 1) return 13; // naprzeciwko dolnego słupka przeciwnika
- if (x == length - 1 && y == width / 2) return 14; // naprzeciwko bramki twojej
- if (x == length - 1 && y == (width / 2) - 1) return 15; // naprzeciwko górnego słupka twojej
- if (x == length - 1 && y == (width / 2) + 1) return 16; // naprzeciwko dolnego słupka twojej
- if (x == 1 && y > (width / 2) + 1) return 17; // dolne bramkowe przeciwnika
- if (x == 1 && y < (width / 2) - 1) return 18; // górne bramkowe przeciwnika
- if (x == length - 1 && y > (width / 2) + 1) return 19; // dolne bramkowe twoje
- if (x == length - 1 && y < (width / 2) - 1) return 20; // górne bramkowe twoje
- if (y < width / 2) return 21; // połowa przeciwnika
- if (y >= width / 2) return 22; // twoja połowa
- }
- if (x == length && y >= (width / 2) - 1 && y <= (width / 2) + 1) return 5; // bramka przeciwnika
- if (x == length && y < (width / 2) - 1) return 6; // nad bramką przeciwnika
- if (x == length && y > (width / 2) + 1) return 7; // pod bramką przeciwnika
- if (x == 0 && y == width / 2) return 8; // twoja bramka
- if (x == 0 && y == (width / 2) - 1) return 23; // górny słupek twojej bramki
- if (x == 0 && y == (width / 2) + 1) return 24; // dolny słupek twojej bramki
- if (x == 1 && y == (width / 2) - 2) return 25; // górny słupek twojej bramki +1/1
- if (x == 1 && y == (width / 2) + 2) return 26; // dolny słupek twojej bramki +1/1
- if (x == 0 && y < width / 2) return 9; // nad twoją bramką
- if (x == 0 && y > width / 2) return 10; // pod twoją bramką
- if (x == length - 1 && y == width / 2) return 11; // naprzeciwko bramki przeciwnika
- if (x == length - 1 && y == (width / 2) - 1) return 12; // naprzeciwko górnego słupka przeciwnika
- if (x == length - 1 && y == (width / 2) + 1) return 13; // naprzeciwko dolnego słupka przeciwnika
- if (x == 1 && y == width / 2) return 14; // naprzeciwko bramki twojej
- if (x == 1 && y == (width / 2) - 1) return 15; // naprzeciwko górnego słupka twojej
- if (x == 1 && y == (width / 2) + 1) return 16; // naprzeciwko dolnego słupka twojej
- if (x == length - 1 && y > (width / 2) + 1) return 17; // dolne bramkowe przeciwnika
- if (x == length - 1 && y < (width / 2) - 1) return 18; // górne bramkowe przeciwnika
- if (x == 1 && y > (width / 2) + 1) return 19; // dolne bramkowe twoje
- if (x == 1 && y < (width / 2) - 1) return 20; // górne bramkowe twoje
- if (y > width / 2) return 21; // połowa przeciwnika
- if (y <= width / 2) return 22; // twoja połowa
- return -1;
- }
- private Direction oppositeDirection(Direction dir)
- {
- if (dir == Direction.Up) return Direction.Down;
- if (dir == Direction.Down) return Direction.Up;
- if (dir == Direction.UpAndRight) return Direction.DownAndLeft;
- if (dir == Direction.DownAndLeft) return Direction.UpAndRight;
- if (dir == Direction.Left) return Direction.Right;
- if (dir == Direction.Right) return Direction.Left;
- if (dir == Direction.RightAndDown) return Direction.LeftAndUp;
- if (dir == Direction.LeftAndUp) return Direction.RightAndDown;
- return dir;
- }
- private Direction[] ownPossibleDirections(Position pos, Move[] _historyMoves, Direction lastDirection)
- {
- int sectorN = ballSector(pos.X, pos.Y, Map.Length, Map.Width);
- List <Direction> list = new List<Direction>();
- List <Direction> list2 = new List<Direction>();
- list.Add(Direction.Up);
- list.Add(Direction.UpAndRight);
- list.Add(Direction.Right);
- list.Add(Direction.RightAndDown);
- list.Add(Direction.Down);
- list.Add(Direction.DownAndLeft);
- list.Add(Direction.Left);
- list.Add(Direction.LeftAndUp);
- list2.Add(Direction.Up);
- list2.Add(Direction.UpAndRight);
- list2.Add(Direction.Right);
- list2.Add(Direction.RightAndDown);
- list2.Add(Direction.Down);
- list2.Add(Direction.DownAndLeft);
- list2.Add(Direction.Left);
- list2.Add(Direction.LeftAndUp);
- int indexer = 0;
- foreach (Direction dir in list2)
- {
- indexer = 0;
- foreach (Move ruch in _historyMoves)
- {
- if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y)
- {
- list.Remove(ruch.Direction);
- if (indexer-1>=0)
- list.Remove(oppositeDirection(_historyMoves[indexer-1].Direction));
- }
- indexer++;
- }
- }
- if (lastDirection == Direction.Up) list.Remove(Direction.Down);
- if (lastDirection == Direction.Down) list.Remove(Direction.Up);
- if (lastDirection == Direction.UpAndRight) list.Remove(Direction.DownAndLeft);
- if (lastDirection == Direction.DownAndLeft) list.Remove(Direction.UpAndRight);
- if (lastDirection == Direction.Left) list.Remove(Direction.Right);
- if (lastDirection == Direction.Right) list.Remove(Direction.Left);
- if (lastDirection == Direction.RightAndDown) list.Remove(Direction.LeftAndUp);
- if (lastDirection == Direction.LeftAndUp) list.Remove(Direction.RightAndDown);
- switch (sectorN)
- {
- case 0:
- list.Remove(Direction.Up);
- list.Remove(Direction.UpAndRight);
- list.Remove(Direction.LeftAndUp);
- list.Remove(Direction.Left);
- list.Remove(Direction.Right);
- break;
- case 2:
- list.Remove(Direction.Down);
- list.Remove(Direction.DownAndLeft);
- list.Remove(Direction.RightAndDown);
- list.Remove(Direction.Left);
- list.Remove(Direction.Right);
- break;
- case 6:
- case 7:
- if (Side == 1)
- {
- list.Remove(Direction.Up);
- list.Remove(Direction.Down);
- list.Remove(Direction.LeftAndUp);
- list.Remove(Direction.Left);
- list.Remove(Direction.DownAndLeft);
- }
- else
- {
- list.Remove(Direction.Up);
- list.Remove(Direction.Down);
- list.Remove(Direction.Right);
- list.Remove(Direction.RightAndDown);
- list.Remove(Direction.UpAndRight);
- }
- break;
- }
- return list.ToArray();
- }
- private bool isWall(Position pos, Move[] _historyMoves)
- {
- int indexer = 0;
- if (pos.X == 0 || pos.X == Map.Length || pos.Y == 0 || pos.Y == Map.Width)
- if(pos.Y != Map.Width/2) return true;
- foreach (Move ruch in _historyMoves)
- {
- if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y) indexer++;
- }
- if (indexer > 0 && indexer < 4) return true;
- return false;
- }
- private bool isPossible(Position _pos, Move[] _historyMoves, Direction[] possibleMoves, Direction direction)
- {
- Position pos = _pos;
- List<Move> ownHistoryMoves = new List<Move>();
- foreach (Move ruch in _historyMoves)
- {
- ownHistoryMoves.Add(ruch);
- }
- if (direction == Direction.Up) pos = new Position(_pos.X, _pos.Y - 1);
- if (direction == Direction.UpAndRight) pos = new Position(_pos.X + 1, _pos.Y - 1);
- if (direction == Direction.Right) pos = new Position(_pos.X + 1, _pos.Y);
- if (direction == Direction.RightAndDown) pos = new Position(_pos.X + 1, _pos.Y + 1);
- if (direction == Direction.Down) pos = new Position(_pos.X, _pos.Y + 1);
- if (direction == Direction.DownAndLeft) pos = new Position(_pos.X - 1, _pos.Y + 1);
- if (direction == Direction.Left) pos = new Position(_pos.X - 1, _pos.Y);
- if (direction == Direction.LeftAndUp) pos = new Position(_pos.X - 1, _pos.Y - 1);
- int sectorN = ballSector(pos.X, pos.Y, Map.Length, Map.Width);
- if ((pos.X == 0 &&pos.Y == 0) || (pos.X == 0 && pos.Y == Map.Width) || (pos.X == Map.Length && pos.Y == 0) || (pos.X == Map.Length && pos.Y == Map.Width))
- return false;
- if (sectorN == 0 || sectorN == 2 || sectorN == 6 || sectorN == 7 || sectorN == 8 || sectorN == 9 || sectorN == 10 || sectorN == 23 || sectorN == 24)
- {
- foreach (Move ruch in _historyMoves)
- {
- if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y)
- return false;
- }
- }
- int indexer = 0;
- if (sectorN == 4)
- {
- foreach (Move ruch in _historyMoves)
- {
- if (ruch.Start.X == pos.X && ruch.Start.Y == pos.Y) indexer++;
- }
- if (indexer == 3)
- return false;
- }
- foreach (Move ruch in _historyMoves)
- {
- if (ruch.Start.X == _pos.X && ruch.Start.Y == _pos.Y && ruch.Direction == direction) return false;
- }
- indexer = 0;
- foreach (Direction dir in possibleMoves)
- if (dir == direction) indexer++;
- if (indexer == 0)
- return false;
- if(isWall(pos, _historyMoves) == true)
- {
- indexer = 0;
- ownHistoryMoves.Add(new Move(false, _pos, direction));
- foreach(Direction dir in ownPossibleDirections(pos, ownHistoryMoves.ToArray(), direction))
- if (isPossible(pos, ownHistoryMoves.ToArray(), ownPossibleDirections(pos, ownHistoryMoves.ToArray(), direction), dir))
- {
- indexer = 1;
- break;
- }
- ownHistoryMoves.Remove(ownHistoryMoves.Last());
- }
- if (indexer == 1)
- return true;
- return false;
- }
- private Direction findBest (Move[] historyMoves, Position ballPosition, Direction[] possibleMoves)
- {
- Side = (int)Map.PlayerSide;
- int sector = ballSector(ballPosition.X, ballPosition.Y, Map.Length, Map.Width);
- switch (sector)
- {
- case 0:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.First();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.Last();
- }
- case 1:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- return possibleMoves.First();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- return possibleMoves.Last();
- }
- case 2:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- return possibleMoves.First();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- return possibleMoves.First();
- }
- case 3:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- return possibleMoves.First();
- }
- case 4:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- return possibleMoves.First();
- }
- case 5:
- if (Side == 1) return possibleMoves.Last();
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- return possibleMoves.First();
- }
- case 6:
- if (Side == 1)
- {
- if(isWall(new Position(ballPosition.X+1, ballPosition.Y+1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X -1 , ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X -1 , ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- return possibleMoves.First();
- }
- case 7:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- return possibleMoves.First();
- }
- else
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- return possibleMoves.Last();
- }
- case 8:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.First();
- }
- case 9:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- return possibleMoves.First();
- }
- case 10:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- return possibleMoves.First();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- return possibleMoves.First();
- }
- case 11:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.Last();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- case 12:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.First();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.Last();
- }
- case 13:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.First();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.Last();
- }
- case 14:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.Last();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.First();
- }
- case 15:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- return possibleMoves.First();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- return possibleMoves.Last();
- }
- case 16:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- return possibleMoves.First();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- return possibleMoves.Last();
- }
- case 17:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.First();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- case 18:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.First();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- case 19:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.First();
- }
- case 20:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.First();
- }
- case 21:
- if (Side == 1)
- {
- if (ballPosition.Y > Map.Width / 2)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.First();
- }
- }
- else
- {
- if (ballPosition.Y > Map.Width / 2)
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- }
- case 22:
- if (Side == 1)
- {
- if (ballPosition.Y > Map.Width / 2)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- return possibleMoves.First();
- }
- }
- else
- {
- if (ballPosition.Y > Map.Width / 2)
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- return possibleMoves.Last();
- }
- }
- case 23:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.Last();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.First();
- }
- case 24:
- if (Side == 1)
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.Last();
- }
- else
- {
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.First();
- }
- case 25:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- return possibleMoves.Last();
- }
- case 26:
- if (Side == 1)
- {
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Up;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Down;
- return possibleMoves.Last();
- }
- else
- {
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y + 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isWall(new Position(ballPosition.X - 1, ballPosition.Y - 1), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isWall(new Position(ballPosition.X + 1, ballPosition.Y), historyMoves))
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.RightAndDown)) return Direction.RightAndDown;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.LeftAndUp)) return Direction.LeftAndUp;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Right)) return Direction.Right;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.UpAndRight)) return Direction.UpAndRight;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.DownAndLeft)) return Direction.DownAndLeft;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Down)) return Direction.Down;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Left)) return Direction.Left;
- if (isPossible(ballPosition, historyMoves, possibleMoves, Direction.Up)) return Direction.Up;
- return possibleMoves.Last();
- }
- case -1:
- if (Side == 1) return possibleMoves.Last();
- return possibleMoves.First();
- default:
- if (Side == 1) return possibleMoves.Last();
- return possibleMoves.First();
- }
- }
- public Direction GetNextMove(Move[] historyMoves, Position ballPosition, Direction[] possibleMoves)
- {
- Side = (int)Map.PlayerSide;
- return findBest(historyMoves, ballPosition, possibleMoves);
- }
- public void StartMatch(FieldData field)
- {
- Map = field;
- allDirections[0] = Direction.Up;
- allDirections[1] = Direction.UpAndRight;
- allDirections[2] = Direction.Right;
- allDirections[3] = Direction.RightAndDown;
- allDirections[4] = Direction.Down;
- allDirections[5] = Direction.DownAndLeft;
- allDirections[6] = Direction.Left;
- allDirections[7] = Direction.LeftAndUp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement