闲的蛋疼:用算法解移动一根火柴问题(二)

本文仅个人娱乐所用。

趁着空闲,把昨天的程序完善了下,做成了一个控制台小游戏。不得不说,我的智商被爆了。

import random


class ActionType:
    Dec = 0 #将火柴移出
    Inc = 1 #将火柴移入
    SelfTrans = 2

class PositionType:
    Default = 0
    FrontEmpty = 1

class Side:
    Left = 0
    Right = 1

class Item:
    def __init__(self,value,positionType,side):
        self.value = value
        self.positionType = positionType
        self.side = side

class Match:

    def __init__(self):
        self.G = {
            0: [1, 1, 1, 1, 1, 1, 0],
            1: [0, 1, 1, 0, 0, 0, 0],
            2: [1, 1, 0, 1, 1, 0, 1],
            3: [1, 1, 1, 1, 0, 0, 1],
            4: [0, 1, 1, 0, 0, 1, 1],
            5: [1, 0, 1, 1, 0, 1, 1],
            6: [1, 0, 1, 1, 1, 1, 1],
            7: [1, 1, 1, 0, 0, 0, 0],
            8: [1, 1, 1, 1, 1, 1, 1],
            9: [1, 1, 1, 1, 0, 1, 1]
        }
        self.M = {}
        self.image_cache = {}

    def _makeImage(self,c):
        image = None
        if c == "+":
            image = [
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "@", "*", "*"],
                ["*", "*", "@", "*", "*"],
                ["@", "@", "@", "@", "@"],
                ["*", "*", "@", "*", "*"],
                ["*", "*", "@", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"]
            ]
        elif c == "-":
            image = [
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["@", "@", "@", "@", "@"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"]
            ]
        elif c == "=":
            image = [
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["@", "@", "@", "@", "@"],
                ["*", "*", "*", "*", "*"],
                ["@", "@", "@", "@", "@"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"],
                ["*", "*", "*", "*", "*"]
            ]
        else:
            d = ord(c) - ord('0')
            if 0 <= d <= 9:
                image = [["*" for j in range(5)] for i in range(9)]
                if self.G[d][0] == 1:
                    image[0][0] = "@"
                    image[0][1] = "@"
                    image[0][2] = "@"
                    image[0][3] = "@"
                    image[0][4] = "@"
                if self.G[d][1] == 1:
                    image[0][4] = "@"
     
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值