49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using Gameboard.ShogiUI.Sockets.Models;
|
|
using PathFinding;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
|
|
namespace Gameboard.ShogiUI.Sockets.Utilities
|
|
{
|
|
public class CoordsToNotationCollection : Dictionary<string, Piece?>, IPlanarCollection<Piece>
|
|
{
|
|
public delegate void ForEachDelegate(Piece element, Vector2 position);
|
|
|
|
public CoordsToNotationCollection() : base(81, StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
}
|
|
|
|
public CoordsToNotationCollection(Dictionary<string, Piece?> board) : base(board, StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
}
|
|
|
|
public Piece? this[Vector2 vector]
|
|
{
|
|
get => this[NotationHelper.ToBoardNotation(vector)];
|
|
set => this[NotationHelper.ToBoardNotation(vector)] = value;
|
|
}
|
|
|
|
public Piece? this[int x, int y]
|
|
{
|
|
get => this[NotationHelper.ToBoardNotation(x, y)];
|
|
set => this[NotationHelper.ToBoardNotation(x, y)] = value;
|
|
}
|
|
|
|
|
|
public void ForEachNotNull(ForEachDelegate callback)
|
|
{
|
|
for (var x = 0; x < 9; x++)
|
|
{
|
|
for (var y = 0; y < 9; y++)
|
|
{
|
|
var position = new Vector2(x, y);
|
|
var elem = this[position];
|
|
if (elem != null)
|
|
callback(elem, position);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|