Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created January 20, 2011 10:57
Show Gist options
  • Save ElemarJR/787729 to your computer and use it in GitHub Desktop.
Save ElemarJR/787729 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using StrongChess.Model.Pieces;
namespace StrongChess.Model.Sets
{
struct PieceSet<TPieceRule>
where TPieceRule : IPieceRule, new()
{
Bitboard _Positions;
public PieceSet(Bitboard positions) : this()
{ this._Positions = positions; }
public IEnumerable<Move> GetMoves(Bitboard friends, Bitboard enemies, bool onlyAttacks = false)
{
foreach (var from in _Positions.GetSettedSquares())
{
Bitboard destinations = Rules.For<TPieceRule>().GetMoveBoard(from, friends, enemies);
if (onlyAttacks) destinations &= enemies;
foreach (var to in destinations.GetSettedSquares())
yield return new Move(from, to);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment