Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
primenumber committed Jun 17, 2024
1 parent 9c39da2 commit 945a4e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct ScoreIsNotRegistered {}

#[derive(Error, Debug)]
pub enum ParseRecordError {
#[error("Failed to parse hand")]
FailedToParseHand,
#[error("Failed to parse hand :{0}")]
FailedToParseHand(String),
#[error("invalid hand")]
InvalidHand,
}
Expand Down Expand Up @@ -82,9 +82,10 @@ impl FromStr for Record {
let splitted = record_str.split_ascii_whitespace().collect::<Vec<_>>();
let l = splitted[0].len();
for i in 0..(l / 2) {
let h = splitted[0][(2 * i)..(2 * i + 2)]
let hand_s = &splitted[0][(2 * i)..(2 * i + 2)];
let h = hand_s
.parse::<Hand>()
.or(Err(ParseRecordError::FailedToParseHand))?;
.or(Err(ParseRecordError::FailedToParseHand(hand_s.to_string())))?;
board = match board.play_hand(h) {
Some(next) => next,
None => {
Expand Down Expand Up @@ -136,6 +137,7 @@ pub fn load_records(path: &Path) -> Result<LoadRecords<File>> {

reader.read_line(&mut buffer)?;
let remain = buffer.trim().parse()?;
buffer.clear();

Ok(LoadRecords {
reader,
Expand Down
6 changes: 4 additions & 2 deletions src/train.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ pub fn gen_dataset(matches: &ArgMatches) {

eprintln!("Parse input...");
let mut boards_with_results = Vec::new();
for record in load_records(Path::new(input_path)).unwrap() {
let mut timeline = record.unwrap().timeline().unwrap();
let input_file = File::open(Path::new(input_path)).unwrap();
for line in BufReader::new(input_file).lines() {
let record = line.unwrap().parse::<Record>().unwrap();
let mut timeline = record.timeline().unwrap();
boards_with_results.append(&mut timeline);
}

Expand Down

0 comments on commit 945a4e6

Please sign in to comment.