zoukankan      html  css  js  c++  java
  • 硬币游戏--代码分析与改进

    我的作业:

    1.登录码云,打开连接http://git.oschina.net/juking2017/Game.git,点击屏幕右上角的fork。

    2.在F盘新建一个目录dizhi,打开Git bash并将码云上的项目clone到该路径下。(http://gitee.com/WangCarmen/Game.git)

    3.下载安装python,打开Game,运行程序,发现缺少模块“numpy”。

     4.打开命令提示符,安装“numpy”。

    键入如图所示

    再键入python -m pip install -U pip setuptools

              pyton -m pip install matplotlib

    5.重新运行程序,出现问题并进行更改后,程序运行如下图。

    代码程序:

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    import matplotlib.pyplot as plt
    
    from matplotlib import mlab
    from matplotlib import rcParams
    
    import numpy as np
    import random
    
    
    
    
    # 初始参数设置
    Box_sum =500         # 箱子中剩余硬币数量,初始值
    People_Flag= random.randint(1,10)       # flag 模拟人们取硬币或放硬币的概率 1~10 
    Threshold = 2.5        #  阈值,可调: 1~Threshold 为取硬币,Threshold+1 ~10 为放硬币
    Max_TakeCoin = 5       #  最多可取硬币数量
    Max_DonateCoin = 1     #  最多可放硬币数量
    
    delata=0                # 取、放硬币数量
    Box_per_remain= [500]   # 每次箱子中硬币余额,list
    
    
    # 算法模拟
    for x in range(1,5000):  # 循环次数表示参与人数
         flag= random.randint(1,10) # flag 模拟人们取硬币或放硬币的概率 
         if flag > Threshold:
             # 放硬币
             delta=random.randint(1,Max_DonateCoin)
             delta=random.randint(1,delta)          # 模拟了人们捐款可能性,有偏少的倾向
             Box_sum =Box_sum + delta
             Box_per_remain.append(Box_sum)
         else:
             # 取硬币
             delta=random.randint(1,Max_TakeCoin)
             delta=random.randint(delta,Max_TakeCoin) # 模拟了人 取硬币的可能性,偏多的倾向
             if Box_sum < delta:
                 Box_sum =0                           # 如果不够取,则取光
             else:
                 Box_sum =Box_sum - delta
             Box_per_remain.append(Box_sum)
    
    print(Box_per_remain)
    
    
    # 绘图区
    fig = plt.figure()
    
    ## 1. 标题、X、Y 轴 label
    plt.title('Subway testing')
    plt.xlabel('Time')
    plt.ylabel('Money remained')
    
    x= np.arange(len(Box_per_remain))
    
    ## 2. data
    
    plt.plot(x,Box_per_remain,color='r')
    plt.bar(x,Box_per_remain,alpha=.5,color='g')
    
    plt.show()

    更改:

    1.按照字母顺序排序

         

    2.运算符左右要加空格

       

    提交:

    1.第一次进行提交出现如下问题:

    2.添加用户邮箱和用户名

     

    3.按照给出的代码进行提交,提交成功。

    我的远端仓库连接:https://gitee.com/WangCarmen/Game/commit/65fecc6f9628506c06ae50638a982b9ef84e0608

  • 相关阅读:
    How to change hostname on SLE
    How to install starDIct on suse OS?
    python logging usage
    How to reset password for unknow root
    How to use wget ?
    How to only capute sub-matched character by grep
    How to inspect who is caller of func and who is the class of instance
    How to use groovy script on jenkins
    Vim ide for shell development
    linux高性能服务器编程 (二) --IP协议详解
  • 原文地址:https://www.cnblogs.com/WangJiawen/p/7569859.html
Copyright © 2011-2022 走看看