[−][src]Module connect6::agent
Agent for playing game with given policy
This module consists of two structures, Agent
and AsyncAgent
.
Agent
is implementation of loop based single policy agent.
As we pass the policy, method play
return the PlayResult
consisted of winner and playing history (called path).
AsyncAgent
is multi-thread based agent, playing multiple games asynchronously.
It pass the policy generator and return the vector of PlayResult
.
Examples
Play single game with single policy.
let mut policy = RandomPolicy::new(); let mut agent = Agent::new(&mut policy); let result = agent.play(); assert!(result.is_ok()); println!("winner: {:?}", result.unwrap().winner);
Play multiple game asynchronously.
let policy_gen = || RandomPolicy::new(); let async_agent = AsyncAgent::debug(policy_gen); let result = async_agent.run(4); println!("ratio: {}", result.iter().map(|x| x.winner as i32).sum::<i32>()); assert_eq!(result.len(), 4);
Structs
Agent | Loop based single policy agent. |
AsyncAgent | Agent for playing multiple games asynchronously. |
Path | Unit of playing history, turn, board and selected position. |
PlayResult | Result of playing game, consists of winner and path (history of game). |