SuperPlan(3)TaoBao Winner - UI - RequiredJS Grunt

SuperPlan(3)TaoBao Winner - UI - RequiredJS Grunt

4. RequireJS http://requirejs.org/
Follow the document here http://requirejs.org/docs/jquery.html
Add RequiredJS
Download the file from here http://requirejs.org/docs/download.html

I just go through the simple example to get an idea of how it works.

Here is the sample of requires_demo.html
<html]]>
<head]]>
<title]]>jQuery+RequireJS</title]]>
<scriptdata-main="scripts/main"src="./scripts/require-jquery.js"></script]]>
</head]]>
<body]]>
<h1]]>jQuery+RequireJS</h1]]>
</body]]>

</html]]>

It will load the min.'s in the scripts directory. main.js
require([ "jquery", "jquery.plugin1", "jquery.plugin2" ], function($) {
// the jquery.alpha.js and jquery.beta.js plugins have been loaded.
$(function() {
$('body').sayhello1().sayhello2(); });

});

jquery.plugin1.js
$.fn.sayhello1 = function() {
return this.append('<p>Sillycat, go and go!</p>');
};


jquery.plugin2.js
$.fn.sayhello2 = function() {
return this.append('<p>Kiko, go and go!</p>');
};


the main.js will load the other 2 plugins.

5. Grunt http://gruntjs.com/
Grunt and gruntplugins are installed and managed by nom, node.js package manager.
I love nodeJS, I used to read some documents and examples about nodeJS.

Install GRUNT Command Line Interface(CLI)
Make sure I did not installed any old version.
>npm uninstall -g grunt
>sudo npm install -g grunt-cli

After I installed that, it lives here
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt

>grunt -help
grunt-cli: The grunt command line interface. (v0.1.7)

I will try the first example from here https://github.com/blenderbox/grunt-example and try to understand that.
>git checkout https://github.com/blenderbox/grunt-example.git
>cd grunt-example
>npm install
npm command will install all the package we needs in directory node_modules

>grunt --help
We can see a lot of useful commands. But when I tried
>grunt server

Error Messages:
Running "server" task

Running "clean:server" (clean) task

Running "compass:server" (compass) task
Warning: You need to have Ruby and Compass installed and in your system PATH for this task to work. More info: https://github.com/gruntjs/grunt-contrib-compass Use --force to continue.

Aborted due to warnings.

Solution:
Follow the document in that URL https://github.com/gruntjs/grunt-contrib-compass

First verify if I have ruby
>ruby -v
ruby 1.8.7

>sudo gem update --system
>sudo gem install compass

It works. Go back to the command line and enter
>grunt server
I can visit the page http://localhost:9000

Execute the command just like ant
>grunt

In the app directory, we have images, scripts and styles.

We use sassy CSS in application.scss. And index.html import all the CSS and Scripts separately.

The most import files are package.json and Gruntfile.js.

In the package.json, we have all the dependencies files.
{
"name": "grunt-example",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-concat": "~0.1.2",
"grunt-contrib-coffee": "~0.4.0",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-compass": "~0.2.0",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-cssmin": "~0.4.1",
"grunt-contrib-connect": "0.1.2",
"grunt-contrib-clean": "0.4.0",
"grunt-contrib-htmlmin": "0.1.1",
"grunt-contrib-imagemin": "0.1.2",
"grunt-contrib-livereload": "0.1.1",
"grunt-usemin": "~0.1.9",
"grunt-regarde": "~0.1.1",
"grunt-open": "~0.2.0",
"matchdep": "~0.1.1"
},
"engines": {
"node": ">=0.8.0"
}
}


The file Grntfile.js is something like build.xml, it is powerful and magic. It can run a server based on node js. Compass the CSS and javascript. It almost can do everything based on web design.

I can understand this configuration file Gruntfile.js, but that is not in detail. Maybe I can know more after backbone.

6. SSI
http://sillycat.iteye.com/blog/1075378
come soon…


7. Backbone
come soon…

References:
NodeJS 1~3
http://sillycat.iteye.com/blog/1453848
http://sillycat.iteye.com/blog/1460938
http://sillycat.iteye.com/blog/1462736

RequireJS
http://requirejs.org/
http://www.ibm.com/developerworks/cn/web/1209_shiwei_requirejs/
http://www.cnblogs.com/zhujl/archive/2011/12/30/2302110.html
http://www.jaceju.net/blog/archives/beginning-requirejs/

Grunt
https://github.com/blenderbox/grunt-example

sassy CSS
http://blog.meituo.net/2011/03/27/sass-%E4%BD%BF%E7%94%A8%E4%BB%8B%E7%BB%8D/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Alpha-Beta剪枝算法实现井字棋的示例代码: ```python # 定义玩家和电脑的标记 player = "X" computer = "O" # 初始化棋盘 board = [" " for i in range(9)] # 打印棋盘 def print_board(): row1 = "|".join(board[0:3]) row2 = "|".join(board[3:6]) row3 = "|".join(board[6:9]) print(row1) print("-" * 5) print(row2) print("-" * 5) print(row3) # 判断是否有空位 def has_space(): return " " in board # 判断是否有获胜者 def has_winner(): # 判断行 for i in range(0, 9, 3): if board[i] == board[i+1] == board[i+2] != " ": return True # 判断列 for i in range(3): if board[i] == board[i+3] == board[i+6] != " ": return True # 判断对角线 if board[0] == board[4] == board[8] != " " or board[2] == board[4] == board[6] != " ": return True return False # 评估函数 def evaluate(): if has_winner(): if player == "X": return 0 else: return 2 else: return 1 # 极小化极大算法 def minimax(alpha, beta, depth, is_maximizing): if has_winner(): return evaluate() elif not has_space(): return evaluate() elif depth == 0: return 1 if is_maximizing: best_score = -float("inf") for i in range(9): if board[i] == " ": board[i] = computer score = minimax(alpha, beta, depth-1, False) board[i] = " " best_score = max(score, best_score) alpha = max(alpha, score) if beta <= alpha: break return best_score else: best_score = float("inf") for i in range(9): if board[i] == " ": board[i] = player score = minimax(alpha, beta, depth-1, True) board[i] = " " best_score = min(score, best_score) beta = min(beta, score) if beta <= alpha: break return best_score # 电脑下棋 def computer_move(): best_score = -float("inf") best_move = None for i in range(9): if board[i] == " ": board[i] = computer score = minimax(-float("inf"), float("inf"), 5, False) board[i] = " " if score > best_score: best_score = score best_move = i board[best_move] = computer # 玩家下棋 def player_move(): valid_move = False while not valid_move: move = input("请输入你的下棋位置(1-9): ") try: move = int(move) - 1 if move >= 0 and move <= 8 and board[move] == " ": board[move] = player valid_move = True else: print("无效的位置,请重新输入!") except: print("无效的输入,请重新输入!") # 游戏循环 while True: print_board() player_move() if has_winner(): print_board() print("你赢了!") break elif not has_space(): print_board() print("平局!") break computer_move() if has_winner(): print_board() print("电脑赢了!") break elif not has_space(): print_board() print("平局!") break ``` 在这个示例中,我们使用了极小化极大算法和Alpha-Beta剪枝算法来实现井字棋游戏。玩家使用X标记,电脑使用O标记。玩家和电脑轮流下棋,直到有一方获胜或者平局。在每次电脑下棋时,我们使用Alpha-Beta剪枝算法来遍历博弈树,以提高搜索效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值