<commit_before>﻿using System;
using System.Numerics;
using System.Collections.Generic;
using System.Text;

namespace Yupi.Model.Domain
{
	[Ignore]
	public class HeightMap
	{
		private short[] Map;

		public virtual int MapSize {
			get {
				return Map.Length;
			}
		}

		public virtual int TotalX { get; private set; }

		public virtual int TotalY { get; private set; }

		private static readonly char[] base32 = new char[] {
			'0', '1', '2', '3', '4', '5', '6', '7',
			'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
			'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
			'o', 'p', 'q', 'r', 's', 't', 'u', 'v'
		};

		public HeightMap (string map)
		{
			// TODO Use other representation internally!
			string[] rows = map.Split ('\r');	
			TotalY = rows.Length;
			TotalX = rows.Length > 0 ? rows [0].Length : 0;

			Map = new short[TotalX * TotalY];

			for (int y = 0; y < TotalY; ++y) {
				for (int x = 0; x < TotalX; ++x) {
					short height = ParseTileChar (rows [y] [x]);
					SetTileHeight (x, y, height);
				}
			}
		}

		public bool IsWalkable (Vector2 position)
		{
			// TODO Implement properly
			return GetTileHeight (position) >= 0;
		}

		public bool IsValidTile (Vector2 position)
		{
			return position.X >= 0
			&& position.Y >= 0
			&& position.Y < TotalY
			&& position.X < TotalX;
		}

		public List<Vector2> GetNeighbours (Vector2 position)
		{
			List<Vector2> neighbours = new List<Vector2> (8);
			for (int x = -1; x <= 1; ++x) {
				for (int y = -1; y <= 1; ++y) {
					if (y == 0 && x == 0) {
						continue;
					}

					Vector2 neighbour = position + new Vector2 (x, y);

					if (IsValidTile (neighbour)) {
						neighbours.Add (neighbour);
					}
				}
			}

			return neighbours;
		}

		private short ParseTileChar (char height)
		{
			if (height == 'x') {
				return -1;
			}

			short index = (short)Array.IndexOf (base32, height);

			if (index < 0) {
				throw new ArgumentOutOfRangeException ("height");
			}

			return index;
		}

		private void SetTileHeight (int x, int y, short height)
		{
			Map [x * TotalY + y] = height;
		}

		/// <summary>
		/// The height of the tile with furniture.
		/// </summary>
		/// <returns>The height.</returns>
		/// <param name="x">The x coordinate.</param>
		/// <param name="y">The y coordinate.</param>
		public short GetTileHeight (int x, int y)
		{
			return Map [x * TotalY + y];
		}

		public short GetTileHeight (int index)
		{
			return Map [index];
		}

		public short GetTileHeight (Vector2 position)
		{
			return GetTileHeight ((int)position.X, (int)position.Y);
		}

		public short GetTileHeight (Vector3 position)
		{
			return GetTileHeight ((int)position.X, (int)position.Y);
		}

		/// <summary>
		/// Get the internal map. Should only be used for testing.
		/// </summary>
		/// <returns>The map as string representation</returns>
		public string GetMap ()
		{
			StringBuilder sb = new StringBuilder ();

			for (int x = 0; x < this.TotalX; ++x) {
				for (int y = 0; y < this.TotalY; ++y) {
					short height = GetTileHeight (x, y);

					if (height < 0) {
						sb.Append ("x");
					} else {
						sb.Append (base32 [height]);
					}
				}

				if (x + 1 < this.TotalX) {
					sb.Append ('\r');
				}
			}

			return sb.ToString ();
		}

		public override string ToString ()<commit_msg>Fixed Map representation<commit_after>﻿using System;
using System.Numerics;
using System.Collections.Generic;
using System.Text;

namespace Yupi.Model.Domain
{
	[Ignore]
	public class HeightMap
	{
		private short[] Map;

		public virtual int MapSize {
			get {
				return Map.Length;
			}
		}

		public virtual int TotalX { get; private set; }

		public virtual int TotalY { get; private set; }

		private static readonly char[] base32 = new char[] {
			'0', '1', '2', '3', '4', '5', '6', '7',
			'8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
			'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
			'o', 'p', 'q', 'r', 's', 't', 'u', 'v'
		};

		public HeightMap (string map)
		{
			// TODO Use other representation internally!
			string[] rows = map.Split ('\r');	
			TotalY = rows.Length;
			TotalX = rows.Length > 0 ? rows [0].Length : 0;

			Map = new short[TotalX * TotalY];

			for (int y = 0; y < TotalY; ++y) {
				for (int x = 0; x < TotalX; ++x) {
					short height = ParseTileChar (rows [y] [x]);
					SetTileHeight (x, y, height);
				}
			}
		}

		public bool IsWalkable (Vector2 position)
		{
			// TODO Implement properly
			return GetTileHeight (position) >= 0;
		}

		public bool IsValidTile (Vector2 position)
		{
			return position.X >= 0
			&& position.Y >= 0
			&& position.Y < TotalY
			&& position.X < TotalX;
		}

		public List<Vector2> GetNeighbours (Vector2 position)
		{
			List<Vector2> neighbours = new List<Vector2> (8);
			for (int x = -1; x <= 1; ++x) {
				for (int y = -1; y <= 1; ++y) {
					if (y == 0 && x == 0) {
						continue;
					}

					Vector2 neighbour = position + new Vector2 (x, y);

					if (IsValidTile (neighbour)) {
						neighbours.Add (neighbour);
					}
				}
			}

			return neighbours;
		}

		private short ParseTileChar (char height)
		{
			if (height == 'x') {
				return -1;
			}

			short index = (short)Array.IndexOf (base32, height);

			if (index < 0) {
				throw new ArgumentOutOfRangeException ("height");
			}

			return index;
		}

		private void SetTileHeight (int x, int y, short height)
		{
			Map [x * TotalY + y] = height;
		}

		/// <summary>
		/// The height of the tile with furniture.
		/// </summary>
		/// <returns>The height.</returns>
		/// <param name="x">The x coordinate.</param>
		/// <param name="y">The y coordinate.</param>
		public short GetTileHeight (int x, int y)
		{
			return Map [x * TotalY + y];
		}

		public short GetTileHeight (int index)
		{
			return Map [index];
		}

		public short GetTileHeight (Vector2 position)
		{
			return GetTileHeight ((int)position.X, (int)position.Y);
		}

		public short GetTileHeight (Vector3 position)
		{
			return GetTileHeight ((int)position.X, (int)position.Y);
		}

		/// <summary>
		/// Get the internal map. Should only be used for testing.
		/// </summary>
		/// <returns>The map as string representation</returns>
		public string GetMap ()
		{
			StringBuilder sb = new StringBuilder ();

			for (int y = 0; y < this.TotalY; ++y) {
				for (int x = 0; x < this.TotalX; ++x) {
					short height = GetTileHeight (x, y);

					if (height < 0) {
						sb.Append ("x");
					} else {
						sb.Append (base32 [height]);
					}
				}

				if (y + 1 < this.TotalY) {
					sb.Append ('\r');
				}
			}

			return sb.ToString ();
		}

		public override string ToString ()
{'fraction_non_alphanumeric': 0.1642541520646046, 'fraction_numerical': 0.01432271826908426, 'mean_word_length': 2.5045381740523225, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '506789', 'n_tokens_mistral': 2859, 'n_tokens_neox': 2294, 'n_words': 712}