ProofUtil.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include "Hex.hpp"
00007 #include "BoardUtils.hpp"
00008 #include "BitsetIterator.hpp"
00009 #include "DfsSolver.hpp"
00010 #include "ProofUtil.hpp"
00011 #include "SortedSequence.hpp"
00012
00013 using namespace benzene;
00014
00015
00016
00017 bitset_t ProofUtil::MaximumProofSet(const HexBoard& brd, HexColor toPlay)
00018 {
00019 return brd.GetPosition().GetEmpty()
00020 | brd.GetPosition().GetPlayed(toPlay)
00021 | brd.GetInferiorCells().DeductionSet(toPlay);
00022 }
00023
00024 bitset_t ProofUtil::InitialProofForOpponent(const HexBoard& brd,
00025 HexColor toPlay)
00026 {
00027
00028 const InferiorCells& inf = brd.GetInferiorCells();
00029 bitset_t proof = brd.GetPosition().GetPlayed(!toPlay);
00030 proof |= inf.DeductionSet(!toPlay);
00031
00032
00033 const VCList& lst = brd.Cons(!toPlay).GetList(VC::SEMI,
00034 HexPointUtil::colorEdge1(!toPlay),
00035 HexPointUtil::colorEdge2(!toPlay));
00036 const bool useGreedy = brd.Builder().Parameters().use_greedy_union;
00037 proof |= useGreedy ? lst.getGreedyUnion() : lst.getUnion();
00038
00039
00040
00041
00042
00043
00044
00045
00046 for (BitsetIterator p(inf.Reversible()); p; ++p)
00047 {
00048 const std::set<HexPoint>& reversers = inf.Reversers(*p);
00049 proof.set(*reversers.begin());
00050 }
00051
00052
00053
00054
00055 for (BitsetIterator p(inf.Vulnerable()); p; ++p)
00056 {
00057 const std::set<VulnerableKiller>& killers = inf.Killers(*p);
00058 proof.set((*killers.begin()).killer());
00059 proof |= ((*killers.begin()).carrier());
00060 }
00061 return proof;
00062 }
00063
00064 bool ProofUtil::ShrinkProof(bitset_t& proof, const StoneBoard& board,
00065 HexColor loser, const ICEngine& ice)
00066 {
00067 StoneBoard brd(board.Width(), board.Height());
00068 PatternState pastate(brd);
00069 Groups groups;
00070
00071
00072 bitset_t cells_outside_proof = (~proof & brd.Const().GetCells());
00073 brd.AddColor(loser, cells_outside_proof);
00074
00075
00076 HexColor winner = !loser;
00077 brd.AddColor(winner, board.GetPlayed(winner) & proof);
00078 pastate.Update();
00079 GroupBuilder::Build(brd, groups);
00080
00081
00082 InferiorCells inf;
00083 ice.ComputeFillin(loser, groups, pastate, inf,
00084 HexColorSetUtil::Only(loser));
00085 HexAssert(inf.Captured(winner).none());
00086
00087 bitset_t filled = inf.Dead() | inf.Captured(loser);
00088 bitset_t shrunk_proof = proof - filled;
00089 bool shrunkTheProof = shrunk_proof.count() < proof.count();
00090 proof = shrunk_proof;
00091 return shrunkTheProof;
00092 }
00093
00094