示例#1
0
func PlayOneTurn() (err error) {
	// Release the touchscreen in case interrupted mid event.
	defer TS.FingerUp()

	img, err := screencap.NewScreenCap()
	if err != nil {
		return
	}
	defer func() { err = img.Close() }()

	// Read the screen.
	board, err := screenreader.ReadScreen(img)
	if err != nil {
		return
	}

	fmt.Println(board)

	// Play a move.
	err = MakeMove(board.ChooseMove(-1))
	if err != nil {
		fmt.Println(err)
	}
	return
}
示例#2
0
func init() {
	// Take a screencap to get the screen's size.
	img, err := screencap.NewScreenCap()
	if err != nil {
		panic(err)
	}
	defer func() {
		if err := img.Close(); err != nil {
			panic(err)
		}
	}()
	// Open the touchscreen device.
	TS, err = touchscreen.New("/dev/input/event0", img.Bounds())
	if err != nil {
		TS.Device.Close()
		panic(err)
	}
}