Пример #1
0
func (t *knight) GetMoves(curPos core.Position, b *Board) []core.Position {
	pos := []core.Position{
		curPos.Add(core.Offset{1, 2}),
		curPos.Add(core.Offset{2, 1}),
		curPos.Add(core.Offset{1, -2}),
		curPos.Add(core.Offset{2, -1}),
		curPos.Add(core.Offset{-1, 2}),
		curPos.Add(core.Offset{-2, 1}),
		curPos.Add(core.Offset{-1, -2}),
		curPos.Add(core.Offset{-2, -1}),
	}
	return b.trimInvalidPos(pos, t.GetPlayer())
}
Пример #2
0
func (t *pawn) GetMoves(curPos core.Position, b *Board) []core.Position {
	pos := []core.Position{}
	// forward move
	forward := curPos.Add(core.Offset{0, t.GetPlayer().ForwardDir()})
	if b.OnBoard(forward) && b.GetPos(forward) == nil {
		pos = append(pos, forward)
	}
	// first move
	if !t.HasMoved() {
		forward2 := forward.Add(core.Offset{0, t.GetPlayer().ForwardDir()})
		if b.OnBoard(forward2) && b.GetPos(forward) == nil && b.GetPos(forward2) == nil {
			pos = append(pos, forward2)
		}
	}
	// captures
	cap1 := curPos.Add(core.Offset{1, t.GetPlayer().ForwardDir()})
	if b.isCapture(cap1, t.GetPlayer()) {
		pos = append(pos, cap1)
	}
	cap2 := curPos.Add(core.Offset{-1, t.GetPlayer().ForwardDir()})
	if b.isCapture(cap2, t.GetPlayer()) {
		pos = append(pos, cap2)
	}
	return pos
}
Пример #3
0
func (b *Board) indexPos(v core.Position) int {
	return b.index(v.Column(), v.Row())
}
Пример #4
0
func (b *Board) OnBoard(v core.Position) bool {
	c := int(v.Column())
	r := int(v.Row())
	return c >= 0 && c < b.width && r >= 0 && r < b.height
}
Пример #5
0
func (t *king) GetMoves(curPos core.Position, b *Board) []core.Position {
	pos := []core.Position{
		curPos.Add(core.Offset{0, 1}),
		curPos.Add(core.Offset{1, 1}),
		curPos.Add(core.Offset{-1, 1}),
		curPos.Add(core.Offset{0, -1}),
		curPos.Add(core.Offset{1, -1}),
		curPos.Add(core.Offset{-1, -1}),
		curPos.Add(core.Offset{1, 0}),
		curPos.Add(core.Offset{-1, 0}),
	}
	return b.trimInvalidPos(pos, t.GetPlayer())
}