예제 #1
0
파일: think.go 프로젝트: haramako/work
func ListKikiInto(b *Node, pos shogi.Pos, r []shogi.Pos) []shogi.Pos {
	koma := b.Cell(pos)
	if koma.Kind() == shogi.NN {
		return r
	}

	// 通常の移動
	dir := koma.Player().Dir()
	for _, to := range shogi.KomaMoveList[koma.Kind()] {
		to_pos := shogi.MakePos(pos.X()+to[0], pos.Y()+dir*to[1])
		if !to_pos.InSide() {
			continue
		}
		to_koma := b.Cell(to_pos)
		if to_koma != shogi.Blank && to_koma.Player() == koma.Player() {
			continue
		}
		r = append(r, to_pos)
	}

	// 複数マス直進する移動
	switch koma.Kind() {
	case shogi.KY:
		kikiStraight(b, &r, pos, koma.Player(), koma.Player().Dir(), 0)
	case shogi.HI, shogi.RY:
		kikiStraight(b, &r, pos, koma.Player(), 1, 0)
		kikiStraight(b, &r, pos, koma.Player(), -1, 0)
		kikiStraight(b, &r, pos, koma.Player(), 0, 1)
		kikiStraight(b, &r, pos, koma.Player(), 0, -1)
	case shogi.KA, shogi.UM:
		kikiStraight(b, &r, pos, koma.Player(), 1, 1)
		kikiStraight(b, &r, pos, koma.Player(), -1, 1)
		kikiStraight(b, &r, pos, koma.Player(), 1, -1)
		kikiStraight(b, &r, pos, koma.Player(), -1, -1)
	}

	return r
}
예제 #2
0
파일: think.go 프로젝트: haramako/work
func kikiStraight(b *Node, list *[]shogi.Pos, pos shogi.Pos, player shogi.Player, dy int, dx int) {
	for {
		pos = shogi.MakePos(pos.X()+dx, pos.Y()+dy)
		if !pos.InSide() {
			break
		}
		koma := b.Cell(pos)
		*list = append(*list, pos)
		if koma != shogi.Blank {
			break
		}
	}
}