コード例 #1
0
ファイル: SetupCube.cs プロジェクト: fletcher-berry/Cubing
        // Get a list of colors that the selected node can take
        public List <CubeColor> GetAvailableColors()
        {
            if (SelectedNode == null || SelectedNode.Value != CubeColor.None)
            {
                return(new List <CubeColor>());
            }
            switch (State)
            {
            case SetupState.CP:
                if (SelectedNode.Left.Value == CubeColor.Yellow)
                {
                    List <CubeColor> colors = new List <CubeColor>();
                    foreach (var color in _leftCorners)
                    {
                        colors.Add(color);
                    }
                    return(colors);
                }
                else
                {
                    List <CubeColor> colors = new List <CubeColor>();
                    foreach (var color in _leftCorners)
                    {
                        colors.Add(RecognitionTools.GetRelativeColor(color, ColorCompare.Left));
                    }
                    return(colors);
                }

            case SetupState.EP:
                List <CubeColor> edgeColors = new List <CubeColor>();
                foreach (var color in _edgeColors)
                {
                    edgeColors.Add(color);
                }
                return(edgeColors);

            default:
                return(new List <CubeColor>());
            }
        }
コード例 #2
0
ファイル: SetupCube.cs プロジェクト: fletcher-berry/Cubing
        // during permutation phase, user uses keyboard to choose the color of the selected sticker
        public void KeyPress(KeyPressEventArgs e)
        {
            if (SelectedNode == null)
            {
                return;
            }
            Action action = new Action();

            switch (State)
            {
            case SetupState.CP:
                List <CubeColor> available = GetAvailableColors();
                CubeColor        color     = GetCubeColorFromChar(e.KeyChar);
                // if selected color can be placed on the cubbe, place it
                if (color != CubeColor.None && available.Contains(color))
                {
                    SelectedNode.Value = color;
                    action.Pieces.Add(SelectedNode);
                    if (SelectedNode.Left.Value == CubeColor.Yellow)
                    {
                        SelectedNode.Right.Value = RecognitionTools.GetRelativeColor(color, ColorCompare.Left);
                        action.Pieces.Add(SelectedNode.Right);
                        _leftCorners.Remove(color);
                    }
                    else
                    {
                        SelectedNode.Left.Value = RecognitionTools.GetRelativeColor(color, ColorCompare.Right);
                        action.Pieces.Add(SelectedNode.Left);
                        _leftCorners.Remove(RecognitionTools.GetRelativeColor(color, ColorCompare.Right));
                    }
                    SelectedNode = null;
                }
                // if 3 corners have been colored, the other can be colored automatically, then corner permutation is complete
                if (_corners.Count(corner => corner.Head.Value == CubeColor.None || corner.Head.Left.Value == CubeColor.None) == 1)
                {
                    var list = _corners.First(corner => corner.Head.Value == CubeColor.None || corner.Head.Left.Value == CubeColor.None);
                    // find yellow sticker
                    var node = GetYellowNode(list);
                    node.Right.Value = _leftCorners[0];
                    action.Pieces.Add(node.Right);
                    node.Left.Value = RecognitionTools.GetRelativeColor(_leftCorners[0], ColorCompare.Left);
                    action.Pieces.Add(node.Left);
                    _leftCorners.Clear();
                    State = SetupState.EP;
                }
                if (action.Pieces.Count > 0)
                {
                    _actions.Push(action);
                }
                return;

            case SetupState.EP:
                List <CubeColor> availableEdges = GetAvailableColors();
                CubeColor        edgeColor      = GetCubeColorFromChar(e.KeyChar);
                if (edgeColor != CubeColor.None && availableEdges.Contains(edgeColor))
                {
                    SelectedNode.Value = edgeColor;
                    action.Pieces.Add(SelectedNode);
                    _edgeColors.Remove(edgeColor);
                }
                // if 2 edges are colored, the other 2 can be determined because there must be an even number of piece swaps on the cube
                if (_edges.Count(edge => edge.Head.Value == CubeColor.None || edge.Head.Right.Value == CubeColor.None) == 2)
                {
                    bool cornerParity = IsParity(RecognitionTools.CompareColors(GetYellowNode(ULFList).Right.Value, CubeColor.Red),
                                                 RecognitionTools.CompareColors(GetYellowNode(URFList).Right.Value, CubeColor.Green),
                                                 RecognitionTools.CompareColors(GetYellowNode(URBList).Right.Value, CubeColor.Orange));
                    var uncoloredEdges = _edges.Where(edge => edge.Head.Value == CubeColor.None || edge.Head.Right.Value == CubeColor.None).ToArray();
                    GetYellowNode(uncoloredEdges[0]).Right.Value = _edgeColors[0];
                    GetYellowNode(uncoloredEdges[1]).Right.Value = _edgeColors[1];
                    bool edgeParity = IsParity(RecognitionTools.CompareColors(GetYellowNode(UFList).Right.Value, CubeColor.Red),
                                               RecognitionTools.CompareColors(GetYellowNode(URList).Right.Value, CubeColor.Green),
                                               RecognitionTools.CompareColors(GetYellowNode(UBList).Right.Value, CubeColor.Orange));
                    if (cornerParity != edgeParity)
                    {
                        GetYellowNode(uncoloredEdges[0]).Right.Value = _edgeColors[1];
                        GetYellowNode(uncoloredEdges[1]).Right.Value = _edgeColors[0];
                    }
                    action.Pieces.Add(GetYellowNode(uncoloredEdges[0]).Right);
                    action.Pieces.Add(GetYellowNode(uncoloredEdges[1]).Right);
                    _edgeColors.Clear();
                    State = SetupState.Compeleted;
                }
                if (action.Pieces.Count > 0)
                {
                    _actions.Push(action);
                }
                return;

            default:
                return;
            }
        }