~ntietz/isabella-db

29aacce3d533b3bcf4e65f1302ad5ce6f4988bfb — Nicole Tietz-Sokolskaya 1 year, 2 months ago 05442a6
Fix bug in bitwise-and which resulted in skipping lots of games
M bitmap/src/sparse.rs => bitmap/src/sparse.rs +13 -1
@@ 210,7 210,7 @@ impl BitAnd for &SparseBitmap {
                result.runs.push(run);
            }

            if left.start < right.start {
            if left.end() < right.end() {
                left_opt = left_iter.next();
            } else {
                right_opt = right_iter.next();


@@ 338,6 338,18 @@ mod tests {
    }

    #[test]
    fn sparse_bitmap_bitwise_and2() {
        let size = 8;

        let a = bitmap_from_vec(size, vec![0, 1, 2, 3, 4, 5, 6, 7]);
        let b = bitmap_from_vec(size, vec![1, 2, 5, 7]);

        let and_bitm = &a & &b;

        assert_eq!(and_bitm, b);
    }

    #[test]
    fn sparse_bitmap_bitwise_or() {
        let size = 16;


M isabella/src/web/templates.rs => isabella/src/web/templates.rs +10 -5
@@ 29,11 29,12 @@ pub struct AvailableMove {
}

/// Contains the result rates (win, loss, or draw) out of 100, as an integer.
#[derive(Debug)]
#[derive(Clone, Copy, Debug)]
pub struct GameResultStats {
    pub white_wins: f32,
    pub black_wins: f32,
    pub drawn: f32,
    pub total: usize,
}

impl GameResultStats {


@@ 42,12 43,14 @@ impl GameResultStats {
        black_count: usize,
        draw_count: usize,
    ) -> GameResultStats {
        let total = (white_count + black_count + draw_count) as f32;
        let total = white_count + black_count + draw_count;
        let totalf = total as f32;

        GameResultStats {
            white_wins: (white_count as f32 / total) * 100.0,
            black_wins: (black_count as f32 / total) * 100.0,
            drawn: (draw_count as f32 / total) * 100.0,
            white_wins: (white_count as f32 / totalf) * 100.0,
            black_wins: (black_count as f32 / totalf) * 100.0,
            drawn: (draw_count as f32 / totalf) * 100.0,
            total,
        }
    }
}


@@ 133,6 136,8 @@ impl<'a> BoardTemplate<'a> {
            }
        }

        available_moves.sort_by_key(|m| m.stats.map(|s| -(s.total as isize)).unwrap_or(0));

        available_moves
    }


M isabella/src/web/views.rs => isabella/src/web/views.rs +2 -0
@@ 30,6 30,8 @@ pub async fn position(
        None => BoardTemplate::new(context.get_ref()),
    };

    tracing::debug!("rendering template");
    let s = template.render().expect("BoardTemplate should render");
    tracing::debug!("sending response");
    HttpResponse::Ok().content_type("text/html").body(s)
}

M isabella/templates/board.html => isabella/templates/board.html +2 -2
@@ 34,9 34,9 @@
                    <a href="{{ m.url }}">{{ m.san }}</a>
                    {% match m.stats %}
                    {% when Some with (stats) %}
                    white: {{ stats.white_wins }}, black: {{ stats.black_wins }}, draw: {{ stats.drawn }}.
                    white: {{ "{:.1}"|format(stats.white_wins) }}, black: {{ "{:.1}"|format(stats.black_wins) }}, draw: {{ "{:.1}"|format(stats.drawn) }}. games: {{ stats.total }}.
                    {% when None %}
                    It's a novelty!
                    (nil)
                    {% endmatch %}
                </p>
                {% endfor %}