码迷,mamicode.com
首页 > 其他好文 > 详细

amazon 设计 10 puzzle.

时间:2014-08-12 06:51:13      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   ar   art   

class Edge {
    enum Type {
        inner, outer, flat
    }
 
    Piece parent;
    Type type;
 
    boolean fitsWith(Edge type) {
    }; // Inners & outer fit together.
}
 
class Piece {
    Edge left, right, top, bottom;
 
    // 90, 180, etc
    Orientation solvedOrientation = 90;
}
 
class Puzzle {
    // Remaining pieces left to put away.
    Piece[][] pieces;
    Piece[][] solution;
    Edge[] inners, outers, flats;
 
    // We‘re going to solve this by working our way
    // in-wards, starting with the corners.
    // This is a list of the inside edges.
    Edge[] exposed_edges;
 
    void sort() {
 
        // Iterate through all edges,
        // adding each to inners, outers, etc,
        // as appropriate.
        // Look for the corners—add those to solution.
        // Add each non-flat edge of the corner
        // to exposed_edges.
 
    }
 
    void solve() {
        for (Edge edge1 : exposed_edges) {
            // Look for a match to edge1
            if (edge1.type == Edge.Type.inner) {
                for (Edge edge2 : outers) {
                    if (edge1.fitsWith(edge2)) {
                        // We found a match!
                        // Remove edge1 from
                        // exposed_edges.
                        // Add edge2‘s piece
                        // to solution.
                        // Check which edges of edge2
                        // are exposed, and add
                        // those to exposed_edges.
                    }
                }
                // Do the same thing,
                // swapping inner & outer.
            }
        }
    }
}

 

amazon 设计 10 puzzle.,布布扣,bubuko.com

amazon 设计 10 puzzle.

标签:style   blog   color   os   io   for   ar   art   

原文地址:http://www.cnblogs.com/leetcode/p/3906335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!