I'm writing a program to play Chess. My Game
class has the async function play
. This function returns when the game ends, returning a Winner enum, which is either a stalemate or a win for some colour.
In my main
fn, I want to run game.play
, then run game.render()
repeatedly, until game.play
returns a Winner, at which point the loop should stop.
Having attempted to read the docs, I don't really understand why Pinning or Boxing is neccesary in order to poll the future, and I haven't been able to get it working.
The desired code for main
should look something like this:
let textures = piece::Piece::load_all_textures().await;
let mut game = game::Game::new(player::Player::User, player::Player::User);
let future = game.play();
while None = future.poll() {
game.render(textures).await;
next_frame().await;
}
// Do something now that the game has ended
I also understand that I will run into issues with borrow checking with this code, but that's a problem for me to deal with once I figure this one out.
What is the easiest way of attempting what I am trying to do?