bool SequenceEqualPermuted(Tuple <List <int>, List <int> > mapping, SlowBoard other) { for (int i = 0; i < Stacks.Count; i++) { var permutedStack = ApplyMapping(mapping, Stacks[i]); if (permutedStack != other.Stacks[i]) { return(false); } } if (Turn == FixerBreaker.Turn.Fixer) { return(true); } if (LastMove.Stack != other.LastMove.Stack) { return(false); } var ours = new[] { LastMove.Added, LastMove.Removed }; var theirs = new List <int>() { other.LastMove.Added, other.LastMove.Removed }; return(ApplyMapping(mapping, ours).ToList().Equal(theirs)); }
public bool Equals(SlowBoard other) { if (other == null) { return(false); } if (Turn != other.Turn) { return(false); } if (N != other.N) { return(false); } if (Stacks.SequenceEqual(other.Stacks)) { if (Turn == FixerBreaker.Turn.Fixer) { return(true); } if (LastMove.Stack == other.LastMove.Stack && (LastMove.Added == other.LastMove.Added && LastMove.Removed == other.LastMove.Removed || LastMove.Added == other.LastMove.Removed && LastMove.Removed == other.LastMove.Added)) { return(true); } return(false); } return(FindPermutation(other) != null); }
public Tuple <List <int>, List <int> > FindPermutation(SlowBoard other) { if (!Degrees.Select(x => x.Item2).SequenceEqual(other.Degrees.Select(x => x.Item2))) { return(null); } var mappingPairs = new List <Tuple <List <int>, List <int> > >(); for (int i = 0; i < DegreeChangeIndices.Count - 1; i++) { var domain = new List <int>(); var codomain = new List <int>(); for (int j = DegreeChangeIndices[i]; j < DegreeChangeIndices[i + 1]; j++) { domain.Add(Degrees[j].Item1); codomain.Add(other.Degrees[j].Item1); } mappingPairs.Add(new Tuple <List <int>, List <int> >(domain, codomain)); } return(mappingPairs.Select(mp => Permutation.EnumerateAll(mp.Item2.Count).Select(p => new Tuple <List <int>, List <int> >(mp.Item1, p.Apply(mp.Item2)))) .CartesianProduct() .Select(mapping => FlattenMapping(mapping)) .FirstOrDefault(mapping => SequenceEqualPermuted(mapping, other))); }
public SlowBoard Clone() { var clone = new SlowBoard(Stacks.ToList(), Pot); clone.Turn = Turn; clone.LastMove = LastMove; clone._hashCode = _hashCode; clone.ComputeHashCode(); return(clone); }
public bool ExactlyEqual(SlowBoard other) { if (other == null) { return(false); } if (Turn != other.Turn) { return(false); } if (N != other.N) { return(false); } if (Pot != other.Pot) { return(false); } if (Stacks.SequenceEqual(other.Stacks)) { if (Turn == FixerBreaker.Turn.Fixer) { return(true); } if (LastMove.Stack == other.LastMove.Stack && (LastMove.Added == other.LastMove.Added && LastMove.Removed == other.LastMove.Removed || LastMove.Added == other.LastMove.Removed && LastMove.Removed == other.LastMove.Added)) { return(true); } } return(false); }