55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
|
#ifndef ORDLE_H
|
||
|
#define ORDLE_H
|
||
|
|
||
|
#include <iostream>
|
||
|
#include <vector>
|
||
|
#include <string>
|
||
|
#include <map>
|
||
|
#include <algorithm>
|
||
|
#include <sstream>
|
||
|
#include <tuple>
|
||
|
|
||
|
// Helper types and aliases
|
||
|
using size_type = std::string::size_type;
|
||
|
using letters_and_indices = std::map<size_type, std::string>;
|
||
|
|
||
|
// Function declarations
|
||
|
std::vector<std::string> read_candidates(std::istream &input);
|
||
|
|
||
|
bool contains_any_of(const std::string &s, const std::string &cs);
|
||
|
bool contains_at(const std::string &s, char c, size_type pos);
|
||
|
bool contains_but_not_at(const std::string &s, char c, size_type pos);
|
||
|
|
||
|
// Functors
|
||
|
struct wrong_fn {
|
||
|
explicit wrong_fn(const std::string &letters);
|
||
|
bool operator()(const std::string &word) const;
|
||
|
|
||
|
private:
|
||
|
std::string l;
|
||
|
};
|
||
|
|
||
|
struct correct_fn {
|
||
|
explicit correct_fn(const letters_and_indices &idxs);
|
||
|
bool operator()(const std::string &word) const;
|
||
|
|
||
|
private:
|
||
|
letters_and_indices m;
|
||
|
};
|
||
|
|
||
|
struct misplaced_fn {
|
||
|
explicit misplaced_fn(const letters_and_indices &idxs);
|
||
|
bool operator()(const std::string &word) const;
|
||
|
|
||
|
private:
|
||
|
letters_and_indices m;
|
||
|
};
|
||
|
|
||
|
void do_filter(std::vector<std::string> &candidates, const std::string &wrong,
|
||
|
const letters_and_indices &green, const letters_and_indices &yellow);
|
||
|
|
||
|
letters_and_indices build_list(const std::string &line);
|
||
|
std::tuple<std::string, letters_and_indices, letters_and_indices> prompt();
|
||
|
|
||
|
#endif // ORDLE_H
|