<?php

abstract class Animal
{
	public $x;
	public $y;
	
	public function __construct()
	{
		$this->x = mt_rand(1, Field::WIDTH);
		$this->y = mt_rand(1, Field::HEIGHT);
	}	
}

class Mouse extends Animal
{
	const NAME = 'm';
	
	private function getDangers($field)
	{
		$yClone = ($this->y + 4 > Field::HEIGHT) ? $this->y + ($this->y + 4 - Field::HEIGHT) : $this->y + 4;
		$j = ($this->y - 4 < 0) ? $this->y - 4 : 0;
		
		$i = ($this->x - 4 < 0) ? $this->x - 4 : 0;
		$xClone = ($this->x + 4 > Field::HEIGHT) ? $this->x + ($this->x + 4 - Field::HEIGHT) : $this->x + 4;
		
		for ($j; $j < $yClone; $j++) {
			for ($i; $i < $xClone; $i++) {
				if ($field[$j][$i] == Cat::NAME) {
					$dangers[] = array($j, $i);
				}
			}
		}
		
		return $dangers;
	}
	
	public function getPossibleSteps($field)
	{
		$dangers = $this->getDangers($field);
		
		$possibleSteps[] = $field[$this->y - 1][$this->x];
		$possibleSteps[] = $field[$this->y][$this->x + 1];
		$possibleSteps[] = $field[$this->y + 1][$this->x];
		$possibleSteps[] = $field[$this->y][$this->x - 1];
		
		foreach ($possibleSteps as $step) {
			foreach ($dangers as $danger) {
				if ($step == $danger) {
					unset($dangers[$danger]);
					sort($dangers);
				}
			}
		}
		return $possibleSteps;
	}
}

class Cat extends Animal
{
	const NAME = 'C';
	
}

class Field
{
	const HEIGHT = 8;
	const WIDTH = 16;
	
	public $field;
	
	public static function getField()
	{
		for ($y = 0; $y < self::HEIGHT; $y++) {
			for ($x = 0; $x < self::WIDTH; $x++) {
				$field[$y][$x] = ".";
			}
		}
		
		return $field;
	}
	
	public function isCorner($x, $y)
	{
		if ($x == self::WIDTH && $y == self::HEIGHT) {
			return true;
		} else {
			return false;
		}
	}
}

class Game
{
	
}

$field = new Field;

$m1 = new Mouse;

foreach (Field::getField() as $string) {
	echo implode("", $string)."\n";
}
