Project3:Ants Vs. SomeBees

news2024/11/10 23:16:20

Ants Vs. SomeBees

    • 1. 前言
    • 2. Phase 1:Basic gameplay
    • 3. Phase 2:More Ants!
    • 4. Phase 3: Water and Might
    • 5. 测试结果

1. 前言

本项目是 CS 61A 的第三个项目,要求是实现一个类似于植物大战僵尸的游戏,这里 Ants 就相当于是植物,Bees 就是僵尸。

一共三个 Phase,在ants.py中实现相关函数。具体实现按照文档说明一步步实现。

2. Phase 1:Basic gameplay

Phase 1 是实现 HarvestAnt 和 ThrowerAnt。
HarvesterAnt 类似于 “向日葵”,ThrowerAnt 类似于 “豌豆射手”。

class Place:
    """A Place holds insects and has an exit to another Place."""
    is_hive = False

    def __init__(self, name, exit=None):
        """Create a Place with the given NAME and EXIT.

        name -- A string; the name of this Place.
        exit -- The Place reached by exiting this Place (may be None).
        """
        self.name = name
        self.exit = exit
        self.bees = []        # A list of Bees
        self.ant = None       # An Ant
        self.entrance = None  # A Place
        # Phase 1: Add an entrance to the exit
        # BEGIN Problem 2
        "*** YOUR CODE HERE ***"
        if self.exit != None:
            self.exit.entrance = self
        # END Problem 2

    def add_insect(self, insect):
        """
        Asks the insect to add itself to the current place. This method exists so
            it can be enhanced in subclasses.
        """
        insect.add_to(self)

    def remove_insect(self, insect):
        """
        Asks the insect to remove itself from the current place. This method exists so
            it can be enhanced in subclasses.
        """
        insect.remove_from(self)

    def __str__(self):
        return self.name

class HarvesterAnt(Ant):
    """HarvesterAnt produces 1 additional food per turn for the colony."""

    name = 'Harvester'
    implemented = True
    food_cost = 2
    # OVERRIDE CLASS ATTRIBUTES HERE

    def action(self, gamestate):
        """Produce 1 additional food for the colony.

        gamestate -- The GameState, used to access game state information.
        """
        # BEGIN Problem 1
        "*** YOUR CODE HERE ***"
        gamestate.food += 1
        # END Problem 1


class ThrowerAnt(Ant):
    """ThrowerAnt throws a leaf each turn at the nearest Bee in its range."""

    name = 'Thrower'
    implemented = True
    damage = 1
    food_cost = 3
    lower_bound = (-1) * float('inf')
    upper_bound = float('inf')
    # ADD/OVERRIDE CLASS ATTRIBUTES HERE

    def nearest_bee(self):
        """Return the nearest Bee in a Place that is not the HIVE, connected to
        the ThrowerAnt's Place by following entrances.

        This method returns None if there is no such Bee (or none in range).
        """
        # BEGIN Problem 3 and 4
        nearest_place = self.place
        distance = 0
        while not nearest_place.is_hive:
            if random_bee(nearest_place.bees) and self.lower_bound <= distance <= self.upper_bound:
                return random_bee(nearest_place.bees)
            nearest_place = nearest_place.entrance
            distance += 1
        return None
        # END Problem 3 and 4

    def throw_at(self, target):
        """Throw a leaf at the TARGET Bee, reducing its health."""
        if target is not None:
            target.reduce_health(self.damage)

    def action(self, gamestate):
        """Throw a leaf at the nearest Bee in range."""
        self.throw_at(self.nearest_bee())

这里比较有意思的是 question 2,
在这里插入图片描述
需要注意,这里的 place 不是用 list 存储的,而是通过 exit 和 entrance 将同一个 tunnel 里的 places 巧妙地连接起来(类似与链表)。

3. Phase 2:More Ants!

Phase 2 是实现另外7种蚂蚁,分别是 LongThrower 和 ShortThrower、FireAnt,WallAnt,HungryAnt,BodyguardAnt,TankAnt。

class ShortThrower(ThrowerAnt):
    """A ThrowerAnt that only throws leaves at Bees at most 3 places away."""

    name = 'Short'
    food_cost = 2
    upper_bound = 3
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 4
    implemented = True   # Change to True to view in the GUI
    
    # END Problem 4


class LongThrower(ThrowerAnt):
    """A ThrowerAnt that only throws leaves at Bees at least 5 places away."""

    name = 'Long'
    food_cost = 2
    lower_bound = 5
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 4
    implemented = True   # Change to True to view in the GUI
    # END Problem 4


class FireAnt(Ant):
    """FireAnt cooks any Bee in its Place when it expires."""

    name = 'Fire'
    damage = 3
    food_cost = 5
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 5
    implemented = True   # Change to True to view in the GUI
    # END Problem 5

    def __init__(self, health=3):
        """Create an Ant with a HEALTH quantity."""
        super().__init__(health)

    def reduce_health(self, amount):
        """Reduce health by AMOUNT, and remove the FireAnt from its place if it
        has no health remaining.

        Make sure to reduce the health of each bee in the current place, and apply
        the additional damage if the fire ant dies.
        """
        # BEGIN Problem 5
        "*** YOUR CODE HERE ***"
        self.health -= amount # 此处不能直接调用 reduce_health, 如果amount大于health, ant就被收回了.
        for bee in self.place.bees[:]:
            bee.reduce_health(amount)
        if self.health <= 0:
            for bee in self.place.bees[:]:
                bee.reduce_health(self.damage)
        super().reduce_health(0)
        # END Problem 5

# BEGIN Problem 6
# The WallAnt class
class WallAnt(Ant):
    name = 'Wall'
    implemented = True
    food_cost = 4 
    def __init__(self, health=4):
        super().__init__(health)
# END Problem 6

# BEGIN Problem 7
# The HungryAnt Class
class HungryAnt(Ant):
    name = 'Hungry'
    implemented = True
    food_cost = 4
    chewing_turns = 3
    def __init__(self, health=1):
        super().__init__(health)
        self.turns_to_chew = 0
    
    def action(self, gamestate):
        if self.turns_to_chew <= 0:
            bee = random_bee(self.place.bees)
            if bee:
                bee.health = 0
                bee.reduce_health(0)
                self.turns_to_chew = self.chewing_turns
        else:
            self.turns_to_chew -= 1  
# END Problem 7


class ContainerAnt(Ant):
    """
    ContainerAnt can share a space with other ants by containing them.
    """
    is_container = True

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.ant_contained = None

    def can_contain(self, other):
        # BEGIN Problem 8a
        "*** YOUR CODE HERE ***"
        if not other.is_container and not self.ant_contained:
            return True
        else:
            return False
        # END Problem 8a

    def store_ant(self, ant):
        # BEGIN Problem 8a
        "*** YOUR CODE HERE ***"
        if self.can_contain(ant):
            self.ant_contained = ant
        # END Problem 8a

    def remove_ant(self, ant):
        if self.ant_contained is not ant:
            assert False, "{} does not contain {}".format(self, ant)
        self.ant_contained = None

    def remove_from(self, place):
        # Special handling for container ants (this is optional)
        if place.ant is self:
            # Container was removed. Contained ant should remain in the game
            place.ant = place.ant.ant_contained
            Insect.remove_from(self, place)
        else:
            # default to normal behavior
            Ant.remove_from(self, place)

    def action(self, gamestate):
        # BEGIN Problem 8a
        "*** YOUR CODE HERE ***"
        if self and self.ant_contained: # 一定要判空
            self.ant_contained.action(gamestate)
        # END Problem 8a


class BodyguardAnt(ContainerAnt):
    """BodyguardAnt provides protection to other Ants."""

    name = 'Bodyguard'
    food_cost = 4
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 8c
    implemented = True   # Change to True to view in the GUI
    def __init__(self, *args, **kwargs):
        super().__init__(2)
    # END Problem 8c

# BEGIN Problem 9
# The TankAnt class
class TankAnt(ContainerAnt):
    name = 'Tank'
    food_cost = 6
    damage = 1
    implemented = True
    def __init__(self, *args, **kwargs):
        super().__init__(2)

    def action(self, gamestate):
        super().action(gamestate)
        for bee in list(self.place.bees):
            bee.reduce_health(self.damage)
# END Problem 9

一定要注意使用对象前,一定要判别对象是否为空。 另外需要注意 reduce_health 的使用细节。

4. Phase 3: Water and Might

Phase 3 是实现 Water 类,以及 ScubaThrower,QueenAnt,SlowThrower。
其中,实现 SlowThrower 不能修改 ThrowerAnt 和 Bee 类,用到了前面学的高阶函数的知识点。

ScubaThrower 和 QueenAnt 的实现:

class Insect:
    """An Insect, the base class of Ant and Bee, has health and a Place."""

    damage = 0
    is_waterproof = False
    # ADD CLASS ATTRIBUTES HERE

    def __init__(self, health, place=None):
        """Create an Insect with a health amount and a starting PLACE."""
        self.health = health
        self.place = place  # set by Place.add_insect and Place.remove_insect

    def reduce_health(self, amount):
        """Reduce health by AMOUNT, and remove the insect from its place if it
        has no health remaining.

        >>> test_insect = Insect(5)
        >>> test_insect.reduce_health(2)
        >>> test_insect.health
        3
        """
        self.health -= amount
        if self.health <= 0:
            self.death_callback()
            self.place.remove_insect(self)

    def action(self, gamestate):
        """The action performed each turn.

        gamestate -- The GameState, used to access game state information.
        """

    def death_callback(self):
        # overriden by the gui
        pass

    def add_to(self, place):
        """Add this Insect to the given Place

        By default just sets the place attribute, but this should be overriden in the subclasses
            to manipulate the relevant attributes of Place
        """
        self.place = place

    def remove_from(self, place):
        self.place = None

    def __repr__(self):
        cname = type(self).__name__
        return '{0}({1}, {2})'.format(cname, self.health, self.place)


class Ant(Insect):
    """An Ant occupies a place and does work for the colony."""

    implemented = False  # Only implemented Ant classes should be instantiated
    food_cost = 0
    is_container = False
    is_damage_doubled = False
    # ADD CLASS ATTRIBUTES HERE

    def __init__(self, health=1):
        """Create an Insect with a HEALTH quantity."""
        super().__init__(health)

    @classmethod
    def construct(cls, gamestate):
        """Create an Ant for a given GameState, or return None if not possible."""
        if cls.food_cost > gamestate.food:
            print('Not enough food remains to place ' + cls.__name__)
            return
        return cls()

    def can_contain(self, other):
        return False

    def store_ant(self, other):
        assert False, "{0} cannot contain an ant".format(self)

    def remove_ant(self, other):
        assert False, "{0} cannot contain an ant".format(self)

    def add_to(self, place):
        if place.ant is None:
            place.ant = self
        else:
            # BEGIN Problem 8b
            if place.ant.is_container and place.ant.can_contain(self):
                place.ant.store_ant(self)
            elif self.is_container and self.can_contain(place.ant):
                self.store_ant(place.ant)
                place.ant = self
            else:
                assert place.ant is None, 'Two ants in {0}'.format(place)
            # END Problem 8b
        Insect.add_to(self, place)

    def remove_from(self, place):
        if place.ant is self:
            place.ant = None
        elif place.ant is None:
            assert False, '{0} is not in {1}'.format(self, place)
        else:
            place.ant.remove_ant(self)
        Insect.remove_from(self, place)

    def double(self):
        """Double this ants's damage, if it has not already been doubled."""
        # BEGIN Problem 12
        "*** YOUR CODE HERE ***"
        if not self.is_damage_doubled:
            self.damage = self.damage * 2
            self.is_damage_doubled = True
        # END Problem 12

class Water(Place):
    """Water is a place that can only hold waterproof insects."""

    def add_insect(self, insect):
        """Add an Insect to this place. If the insect is not waterproof, reduce
        its health to 0."""
        # BEGIN Problem 10
        "*** YOUR CODE HERE ***"
        super().add_insect(insect)
        if not insect.is_waterproof:
            insect.reduce_health(insect.health)
        # END Problem 10

# BEGIN Problem 11
# The ScubaThrower class
class ScubaThrower(ThrowerAnt):
    name = 'Scuba'
    food_cost = 6
    is_waterproof = True
    implemented = True
# END Problem 11

# BEGIN Problem 12


class QueenAnt(ScubaThrower):  # You should change this line
# END Problem 12
    """The Queen of the colony. The game is over if a bee enters her place."""

    name = 'Queen'
    food_cost = 7
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 12
    implemented = True   # Change to True to view in the GUI
    # END Problem 12

    @classmethod
    def construct(cls, gamestate):
        """
        Returns a new instance of the Ant class if it is possible to construct, or
        returns None otherwise. Remember to call the construct() method of the superclass!
        """
        # BEGIN Problem 12
        "*** YOUR CODE HERE ***"
        if not gamestate.is_queenAnt_constructed:
            gamestate.is_queenAnt_constructed = True
            return super().construct(gamestate)
        else:
            return None
        # END Problem 12

    def action(self, gamestate):
        """A queen ant throws a leaf, but also doubles the damage of ants
        in her tunnel.
        """
        # BEGIN Problem 12
        "*** YOUR CODE HERE ***"
        super().action(gamestate)
        place = self.place.exit
        while place != None:
            if place.ant:
                if place.ant.is_container and place.ant.ant_contained:
                    place.ant.ant_contained.double()
                    place.ant.double()
                else:
                    place.ant.double()
            place = place.exit 
        # END Problem 12

    def reduce_health(self, amount):
        """Reduce health by AMOUNT, and if the QueenAnt has no health
        remaining, signal the end of the game.
        """
        # BEGIN Problem 12
        "*** YOUR CODE HERE ***"
        super().reduce_health(amount)
        if self.health <= 0:
            ants_lose()
        # END Problem 12

    def remove_from(self, place):
        return None

SlowThrower 的实现:

def make_slow(action):
    """Return a new action method that calls ACTION every other turn.
    action -- An action method of some Bee
    """
    # BEGIN Problem EC
    "*** YOUR CODE HERE ***"
    def new_action(colony): # 如果时间为偶数,则 bee 停顿。
        if colony.time % 2 == 0:
            action(colony)
    return new_action
    # END Problem EC

def make_stun(action):
    """Return a new action method that does nothing.
    action -- An action method of some Bee
    """
    # BEGIN Problem EC
    "*** YOUR CODE HERE ***"
    def new_action(colony):
        return
    return new_action
    # END Problem EC

def apply_effect(effect, bee, duration):
    """Apply a status effect to a BEE that lasts for DURATION turns."""
    # BEGIN Problem EC
    "*** YOUR CODE HERE ***"
    origin_action = bee.action # bee 的原始 action
    new_action = effect(bee.action) # bee 的 新的 action

    def action(colony):
        nonlocal duration
        if duration == 0:
            return origin_action(colony) # 恢复 bee 的 action
        else:
            duration -= 1 # 作用时间减一
            return new_action(colony)

    bee.action = action # 返回新的 action

class SlowThrower(ThrowerAnt):
    """ThrowerAnt that causes Slow on Bees."""

    name = 'Slow'
    food_cost = 6
    # BEGIN Problem EC
    implemented = True   # Change to True to view in the GUI
    # END Problem EC

    def throw_at(self, target):

        # BEGIN Problem EC
        "*** YOUR CODE HERE ***"
        if self:
            apply_effect(make_slow, target, 5)
        # END Problem EC

因为要求不能修改外部类,但是要用到 time,所以只能通过接受调用的参数 gamestate 来获取 time。所以 throw_at需要三个参数,分别是 self、target,以及 appy_effect 中的 colony。

5. 测试结果

=====================================================================
Assignment: Project 3: Ants Vs. SomeBees
OK, version v1.18.1
=====================================================================

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Scoring tests

---------------------------------------------------------------------
Problem 0
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 1
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 2
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 3
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 4
    Passed: 3
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 5
    Passed: 2
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 6
    Passed: 2
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 7
    Passed: 2
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 8
    Passed: 3
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 8a
    Passed: 0
    Failed: 0
[k..........] 0.0% passed

---------------------------------------------------------------------
Problem 8b
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 8c
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 9
    Passed: 3
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 10
    Passed: 2
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 11
    Passed: 3
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem 12
    Passed: 3
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Problem EC
    Passed: 1
    Failed: 0
[ooooooooook] 100.0% passed

---------------------------------------------------------------------
Point breakdown
    Problem 0: 0.0/0
    Problem 1: 1.0/1
    Problem 2: 1.0/1
    Problem 3: 2.0/2
    Problem 4: 2.0/2
    Problem 5: 3.0/3
    Problem 6: 1.0/1
    Problem 7: 3.0/3
    Problem 8: 3.0/3
    Problem 8a: 0.0/0
    Problem 8b: 0.0/0
    Problem 8c: 0.0/0
    Problem 9: 2.0/2
    Problem 10: 1.0/1
    Problem 11: 1.0/1
    Problem 12: 3.0/3
    Problem EC: 2.0/2

Score:
    Total: 25.0

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/196894.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【redis】redis的过期策略以及内存淘汰机制

前言 今天我们讨论下redis的过期策略以及内存淘汰机制&#xff0c;如果你想要考察一个人对redis的了解&#xff0c;那吗这个问题是必选的&#xff0c;从他对这个问题的回答中&#xff0c;就可以了解到他的redis深浅。 过期策略 先来介绍下&#xff0c;Redis key 过期删除的策…

虹科产品 | 使用Redis企业版数据库为MySQL增添魅力!

MySQL读取数据慢&#xff1f; 难以轻松扩展&#xff1f; 数据搜索效率低&#xff1f; 无法实时分发数据集&#xff1f; 虹科Redis企业版数据库解决方案来了&#xff01;企业将Redis企业版数据库与MySQL一起使用&#xff0c;可以实现企业缓存或复制数据库&#xff0c;从而使应用…

MATLAB 非线性规划

✅作者简介&#xff1a;人工智能专业本科在读&#xff0c;喜欢计算机与编程&#xff0c;写博客记录自己的学习历程。 &#x1f34e;个人主页&#xff1a;小嗷犬的个人主页 &#x1f34a;个人网站&#xff1a;小嗷犬的技术小站 &#x1f96d;个人信条&#xff1a;为天地立心&…

uniapp APP分享;判断用户是否安装APP,已安装直接打开,未安装跳转下载页;uniapp 在外部打开APP(schemes)

场景&#xff1a; A将某商品分享给B&#xff0c;B点击后判断是否安装APP&#xff0c;若安装直接打开&#xff0c;没有安装则跳转下载页&#xff1b; 知识点&#xff1a; uniapp APP分享&#xff1b;判断用户是否安装APP&#xff0c;已安装直接打开&#xff0c;未安装跳转下载…

从零开始的数模(十一)微分方程建模

目录 一、概念 1.1什么是微分方程建模 1.2使用场合 二、基于python的微分方程建模 2.1scipy.integrate.odeint() 函数 ​编辑2.2案例 ​编辑 三、基于MATLAB的微分方程建模 四、偏微分方程的求解 一、概念 1.1什么是微分方程建模 微分方程建模是数学模型的重要方法&am…

AcWing 1081. 度的数量(数位DP)

AcWing 1081. 度的数量&#xff08;数位DP&#xff09;一、问题二 、数位DP三、解析1、题意理解2、题目分析三、代码一、问题 二 、数位DP 这道题是一道数位DP的题目&#xff0c;其实数位DP更像我们在高中阶段学过的排列组合问题中的分类讨论。 数位DP顾名思义就是按照数字的…

B/S端界面控件DevExtreme v22.2新功能 - 如何在日历中显示周数?

DevExtreme拥有高性能的HTML5 / JavaScript小部件集合&#xff0c;使您可以利用现代Web开发堆栈&#xff08;包括React&#xff0c;Angular&#xff0c;ASP.NET Core&#xff0c;jQuery&#xff0c;Knockout等&#xff09;构建交互式的Web应用程序&#xff0c;该套件附带功能齐…

LeetCode-1145. 二叉树着色游戏【深度优先搜索,二叉树】

LeetCode-1145. 二叉树着色游戏【深度优先搜索&#xff0c;二叉树】题目描述&#xff1a;解题思路一&#xff1a;深度优先搜索分别计算x的左子树lsz和右子树rsz的节点个数。那么除去x与其左右子树的父子树的节点个数为n-1-lsz-rsz。贪心的&#xff0c;那么二号玩家其实可以占据…

Java基础学习笔记(十八)—— 转换流、对象操作流

转换流、对象操作流1 转换流1.1 构造方法1.2 指定编码读写2 对象操作流2.1 对象操作流概述2.2 对象序列化流2.3 对象反序列化流2.4 案例1 转换流 1.1 构造方法 转换流就是来进行字节流和字符流之间转换的 InputStreamReader&#xff1a;是从字节流到字符流的桥梁&#xff0c;…

Linux(八)线程概念

1、线程的本质 线程就是一个进程内部的控制序列 是CPU进行执行调度的基本单元。&#xff08;调度一段代码的执行是通过线程完成的&#xff09; 一个进程中至少有一个线程&#xff08;所以进程与线程的数量关系是 一对一 或 一对多&#xff09; 2、为什么把线程称为LWP LWP…

数学建模之熵权法(SPSSPRO与MATLAB)

数学建模之熵权法&#xff08;SPSSPRO与MATLAB&#xff09;一、基本原理对于某项指标&#xff0c;可以用熵值来判断某个指标的离散程度&#xff0c;其信息熵值越小&#xff0c;指标的离散程度越大(表明指标值得变异程度越大&#xff0c;提供的信息量越多)&#xff0c;该指标对综…

Maxout 激活函数与 Max-Feature-Map (MFM)

前言 最近在读 A Light CNN for Deep Face Representation With Noisy Labels 提到 maxout 激活函数&#xff0c;虽然很好理解&#xff0c;激活的时候选取最大值即可&#xff0c;但是具体细节看了看相关的资料反倒混淆了。参考了一个相关的视频&#xff0c;大致屡清楚为什么说…

技术周 | qemu网络收发包流程

通常我们使用qemu创建虚拟机时&#xff0c;会使用下面的选项指定虚拟网卡设备的类型&#xff0c;以及桥接、tap设备参数等&#xff0c;如下&#xff1a; -device选项用于给虚拟机分配虚拟设备&#xff0c;如磁盘设备、网卡设备等 -netdev选项用于配置虚拟设备的后端&#xff0…

MACD底背离选股公式以及技术指标公式

今天介绍MACD底背离选股公式&#xff0c;整体来说编写难度比较大&#xff0c;按照MACD底背离的定义&#xff0c;需要分别找到2个价格波段低点以及快线DIF的2个低点&#xff0c;并进行比较&#xff0c;最终实现选股。 一、MACD底背离选股公式&#xff08;平替版&#xff09; 首先…

ES6 简介(一)

文章目录ES6 简介&#xff08;一&#xff09;一、 概述1、 导读2、 Babel 转码器2.1 是什么2.2 配置文件 .babelrc2.3 命令行转码2.4 babel-node2.5 babel/register2.6 polyfill2.7 浏览器环境二、 变量1、 let2、 const3、 ES6 声明变量4、 顶层对象的属性5、 globalThis 对象…

TCP协议面试灵魂12 问(二)

为什么不是两次&#xff1f; 根本原因: 无法确认客户端的接收能力。 分析如下: 如果是两次&#xff0c;你现在发了 SYN 报文想握手&#xff0c;但是这个包滞留在了当前的网络中迟迟没有到达&#xff0c;TCP 以为这是丢了包&#xff0c;于是重传&#xff0c;两次握手建立好了…

机器视觉高速发展催热人工智能市场,深眸科技深度布局把握新机遇

曾经&#xff0c;冰箱侧身的标签、空调背面不显眼的小螺丝、微波炉角落里的型号编码等质量检测&#xff0c;是工业生产线中最费人工、最难检测的“老大难”。这主要是因为我国家电行业长期以混产为主要生产方式&#xff0c;一条生产线上可能有几十种型号的钣金件产品同时经受质…

文档存储Elasticsearch系列--2 ES内部原理

前言&#xff1a;ES作为nosql 的数据存储&#xff0c;为什么它在承载PB级别的数据的同时&#xff0c;又可以对外提高近实时的高效搜索&#xff0c;它又是通过什么算法完成对文档的相关性分析&#xff1b;又是怎么保证聚合的高效性&#xff1b; 1 ES 分布式文档存储&#xff1a…

人工智能导论——谓词公式化为子句集详细步骤

在谓词逻辑中&#xff0c;有下述定义&#xff1a; 原子&#xff08;atom&#xff09;谓词公式是一个不能再分解的命题。 原子谓词公式及其否定&#xff0c;统称为文字&#xff08;literal&#xff09;。PPP称为正文字&#xff0c;P\neg PP称为负文字。PPP与P\neg PP为互补文字。…

MySQL实战作业示例:从离线文件生成数据库

前言 MySQL实战的课后作业&#xff0c;作业内容具体见 https://bbs.csdn.net/topics/611904749 截至时间是 2023年2月2日&#xff0c;按时提交的同学有一位。确实这次的作业非常有挑战性&#xff0c;作业用到的内容没有百分之百的学过&#xff0c;需要大家进行深入而有效的搜索…