File size: 5,153 Bytes
dd9e164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# test_mapper.py
from inference.game_controller import GameController
from inference.action_mapper import ActionMapper
import time
import os

def test_all_actions():
    """测试所有动作映射"""
    ctrl = GameController()
    mapper = ActionMapper(ctrl)
    
    print("=" * 50)
    print("王者荣耀AI控制测试 - 全面测试")
    print("=" * 50)
    
    # 1. 测试移动(8个方向)
    print("\n[1/4] 测试移动控制...")
    moves = [
        "move_up", "move_down", "move_left", "move_right",
        "move_upleft", "move_upright", "move_downleft", "move_downright"
    ]
    
    for move in moves:
        print(f"  执行: {move}")
        mapper.execute(move)
        time.sleep(0.5)  # 每个动作间隔0.5秒
    
    # 2. 测试战斗技能
    print("\n[2/4] 测试战斗技能...")
    combat_actions = ["attack", "skill_damage", "skill_control"]
    
    for action in combat_actions:
        print(f"  执行: {action}")
        mapper.execute(action)
        time.sleep(0.8)
    
    # 3. 测试战术动作
    print("\n[3/4] 测试战术动作...")
    tactical_actions = ["recall", "heal", "summoner", "enhance", "upgrade"]
    
    for action in tactical_actions:
        print(f"  执行: {action}")
        mapper.execute(action)
        time.sleep(0.8)
    
    # 4. 测试截图功能
    print("\n[4/4] 测试截图功能...")
    try:
        img = ctrl.screenshot()
        timestamp = time.strftime("%Y%m%d_%H%M%S")
        filename = f"screenshot_{timestamp}.png"
        img.save(filename)
        print(f"  截图已保存: {filename}")
        
        # 获取屏幕尺寸
        w, h = ctrl.get_screen_size()
        print(f"  屏幕尺寸: {w}x{h}")
        
        # 显示截图信息
        print(f"  图片尺寸: {img.size}")
        print(f"  图片模式: {img.mode}")
        
    except Exception as e:
        print(f"  截图失败: {e}")
    
    print("\n" + "=" * 50)
    print("测试完成!")
    print("=" * 50)

def test_single_action():
    """交互式测试单个动作"""
    ctrl = GameController()
    mapper = ActionMapper(ctrl)
    
    print("\n=== 交互式测试模式 ===")
    print("可用动作:")
    print("  移动: up, down, left, right, upleft, upright, downleft, downright")
    print("  战斗: attack, damage, control")
    print("  战术: recall, heal, summoner, enhance, upgrade")
    print("  其他: screenshot, quit")
    print("-" * 40)
    
    while True:
        cmd = input("\n请输入动作: ").strip().lower()
        
        if cmd == 'quit':
            print("退出测试")
            break
        elif cmd == 'screenshot':
            try:
                img = ctrl.screenshot()
                filename = "manual_screenshot.png"
                img.save(filename)
                print(f"截图已保存: {filename}")
            except Exception as e:
                print(f"截图失败: {e}")
        elif cmd in ['up', 'down', 'left', 'right', 'upleft', 'upright', 'downleft', 'downright']:
            action = f"move_{cmd}"
            print(f"执行: {action}")
            mapper.execute(action)
        elif cmd in ['attack', 'damage', 'control']:
            if cmd == 'damage':
                action = 'skill_damage'
            elif cmd == 'control':
                action = 'skill_control'
            else:
                action = cmd
            print(f"执行: {action}")
            mapper.execute(action)
        elif cmd in ['recall', 'heal', 'summoner', 'enhance', 'upgrade']:
            print(f"执行: {cmd}")
            mapper.execute(cmd)
        else:
            print(f"未知动作: {cmd}")
        
        time.sleep(0.3)

def test_with_delay():
    """带延迟的循环测试(用于观察)"""
    ctrl = GameController()
    mapper = ActionMapper(ctrl)
    
    print("\n=== 自动循环测试模式 ===")
    print("将依次执行所有动作,每个动作间隔1秒")
    print("按 Ctrl+C 停止\n")
    
    actions = [
        # 移动
        "move_up", "move_down", "move_left", "move_right",
        "move_upleft", "move_upright", "move_downleft", "move_downright",
        # 战斗
        "attack", "skill_damage", "skill_control",
        # 战术
        "recall", "heal", "summoner", "enhance", "upgrade"
    ]
    
    try:
        for i, action in enumerate(actions, 1):
            print(f"[{i}/{len(actions)}] {action}")
            mapper.execute(action)
            time.sleep(1)  # 每个动作间隔1秒
            
        print("\n循环测试完成")
    except KeyboardInterrupt:
        print("\n用户中断测试")

if __name__ == "__main__":
    print("选择测试模式:")
    print("1. 全面测试(一次执行所有动作)")
    print("2. 交互式测试(手动输入动作)")
    print("3. 循环测试(自动循环,可观察)")
    
    choice = input("\n请选择 (1/2/3): ").strip()
    
    if choice == '1':
        test_all_actions()
    elif choice == '2':
        test_single_action()
    elif choice == '3':
        test_with_delay()
    else:
        print("无效选择,运行全面测试")
        test_all_actions()